rubyverse 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +4 -0
- data/HISTORY.txt +3 -0
- data/lib/rubyverse.rb +93 -0
- data/rubyverse.gemspec +16 -0
- metadata +68 -0
data/.yardopts
ADDED
data/HISTORY.txt
ADDED
data/lib/rubyverse.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Parallel Ruby universes ("Rubyverses") - A proposed interface for
|
2
|
+
# parallel, "semi-private" method or method-and-data spaces via
|
3
|
+
# "closely associated" objects.
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
#
|
7
|
+
# require 'rubyverse'
|
8
|
+
#
|
9
|
+
# class Number_Assistant
|
10
|
+
# def initialize (original); @original = original; end
|
11
|
+
# def my_method; "Number assistant for #{@original}"; end
|
12
|
+
# def rubyverse_original; @original; end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# class String_Assistant
|
16
|
+
# def initialize (original); @original = original; end
|
17
|
+
# def my_method; "String assistant for #{@original}"; end
|
18
|
+
# def rubyverse_original; @original; end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# class Assisted
|
22
|
+
# def rubyverse_new (object)
|
23
|
+
# case object
|
24
|
+
# when Numeric then Number_Assistant.new(object)
|
25
|
+
# when String then String_Assistant.new(object)
|
26
|
+
# else self
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# def my_method; "Default assistant"; end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# object = Assisted.new # An object implementing #rubyverse_new
|
34
|
+
# 10.in_rubyverse(object).my_method # "Number assistant for 10"
|
35
|
+
# "hi".in_rubyverse(object).my_method # "String assistant for hi"
|
36
|
+
# nil.in_rubyverse(object).my_method # "Default assistant"
|
37
|
+
#
|
38
|
+
# The Rubyverse module is only for documentation purposes.
|
39
|
+
# The Object class is extended with supporting methods.
|
40
|
+
#
|
41
|
+
# A Rubyverse object is responsible for allocating appropriate parallel
|
42
|
+
# objects for its Rubyverse.
|
43
|
+
#
|
44
|
+
# @author Brian Katzung (briank@kappacs.com), Kappa Computer Solutions, LLC
|
45
|
+
# @license Public Domain
|
46
|
+
# @version 0.0.1
|
47
|
+
module Rubyverse
|
48
|
+
|
49
|
+
VERSION = "0.0.1"
|
50
|
+
|
51
|
+
# Return a parallel object in this Rubyverse corresponding to the
|
52
|
+
# given original object.
|
53
|
+
#
|
54
|
+
# It is invoked by Object#in_rubyverse(rubyverse) upon the first
|
55
|
+
# reference to each Rubyverse for each original object.
|
56
|
+
#
|
57
|
+
# It is recommended that parallel objects be initialized with the
|
58
|
+
# original object and that they override #rubyverse_original to
|
59
|
+
# return it.
|
60
|
+
#
|
61
|
+
# @param original The original object.
|
62
|
+
def rubyverse_new (original); original; end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
# Extends the Object class to support Rubyverses.
|
67
|
+
class Object
|
68
|
+
|
69
|
+
# Return the map of Rubyverses to parallel objects.
|
70
|
+
#
|
71
|
+
# @param create [Boolean] Whether to create the map if it doesn't exist.
|
72
|
+
# @return [Hash]
|
73
|
+
def rubyverse_map (create = true)
|
74
|
+
if create then @rubyverse_map ||= {}
|
75
|
+
else @rubyverse_map
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Return ourselves, the original Rubyverse object.
|
80
|
+
#
|
81
|
+
# Parallel object classes should override this method.
|
82
|
+
def rubyverse_original; self; end
|
83
|
+
|
84
|
+
# Return this object's parallel object in another Rubyverse.
|
85
|
+
#
|
86
|
+
# @param rubyverse [Rubyverse] The desired Rubyverse.
|
87
|
+
def in_rubyverse (rubyverse)
|
88
|
+
rubyverse_map[rubyverse] ||= rubyverse.rubyverse_new self
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
# END
|
data/rubyverse.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rubyverse"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2014-04-13"
|
5
|
+
s.authors = ["Brian Katzung"]
|
6
|
+
s.email = ["briank@kappacs.com"]
|
7
|
+
s.homepage = "http://rubygems.org/gems/rubyverse"
|
8
|
+
s.summary = "Semi-private method spaces in parallel Rubyverses"
|
9
|
+
s.description = "Parallel Ruby universes (\"Rubyverses\") - a proposed interface for parallel, \"semi-private\" method or method-and-data spaces via \"closely associated\" objects."
|
10
|
+
s.license = "Public Domain"
|
11
|
+
|
12
|
+
s.files = Dir.glob("lib/**/*") +
|
13
|
+
%w{rubyverse.gemspec HISTORY.txt .yardopts}
|
14
|
+
s.test_files = Dir.glob("test/**/*.rb")
|
15
|
+
s.require_path = 'lib'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyverse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Brian Katzung
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2014-04-13 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Parallel Ruby universes ("Rubyverses") - a proposed interface for parallel, "semi-private" method or method-and-data spaces via "closely associated" objects.
|
22
|
+
email:
|
23
|
+
- briank@kappacs.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/rubyverse.rb
|
32
|
+
- rubyverse.gemspec
|
33
|
+
- HISTORY.txt
|
34
|
+
- .yardopts
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://rubygems.org/gems/rubyverse
|
37
|
+
licenses:
|
38
|
+
- Public Domain
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.7
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Semi-private method spaces in parallel Rubyverses
|
67
|
+
test_files: []
|
68
|
+
|