rubyverse 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/HISTORY.txt +10 -0
  2. data/lib/rubyverse.rb +45 -19
  3. data/rubyverse.gemspec +2 -2
  4. metadata +3 -3
@@ -1,3 +1,13 @@
1
+ 2014-04-25 Version 1.0.0
2
+
3
+ Parallel object maps are now stored in the Rubyverse instead
4
+ of the original object so that they can go away when the Rubyverse
5
+ does. Object#in_rubyverse now calls Rubyverse#rubyversed (which is
6
+ now responsible for invoking Rubyverse#rubyverse_new to create the
7
+ new object).
8
+
9
+ Accordingly, Object#rubyverse_map is now Rubyverse#rubyverse_map.
10
+
1
11
  2014-04-13 Version 0.0.1
2
12
 
3
13
  First release.
@@ -19,6 +19,7 @@
19
19
  # end
20
20
  #
21
21
  # class Assisted
22
+ # include Rubyverse
22
23
  # def rubyverse_new (object)
23
24
  # case object
24
25
  # when Numeric then Number_Assistant.new(object)
@@ -26,27 +27,33 @@
26
27
  # else self
27
28
  # end
28
29
  # end
29
- #
30
30
  # def my_method; "Default assistant"; end
31
31
  # end
32
32
  #
33
- # object = Assisted.new # An object implementing #rubyverse_new
33
+ # object = Assisted.new
34
+ #
35
+ # object.rubyversed(10).my_method # "Number assistant for 10"
34
36
  # 10.in_rubyverse(object).my_method # "Number assistant for 10"
37
+ #
38
+ # object.rubyversed("hi").my_method # "String assistant for hi"
35
39
  # "hi".in_rubyverse(object).my_method # "String assistant for hi"
40
+ #
41
+ # object.rubyversed(nil).my_method # "Default assistant"
36
42
  # nil.in_rubyverse(object).my_method # "Default assistant"
37
43
  #
38
- # The Rubyverse module is only for documentation purposes.
44
+ # The Rubyverse module provides a reference implementation that may be
45
+ # used to extend objects that will be Rubyverses.
39
46
  # The Object class is extended with supporting methods.
40
47
  #
41
- # A Rubyverse object is responsible for allocating appropriate parallel
42
- # objects for its Rubyverse.
48
+ # A Rubyverse object is responsible for allocating and maintaining a
49
+ # map of appropriate parallel objects for its Rubyverse.
43
50
  #
44
51
  # @author Brian Katzung (briank@kappacs.com), Kappa Computer Solutions, LLC
45
52
  # @license Public Domain
46
- # @version 0.0.1
53
+ # @version 1.0.0
47
54
  module Rubyverse
48
55
 
49
- VERSION = "0.0.1"
56
+ VERSION = "1.0.0"
50
57
 
51
58
  # Return a parallel object in this Rubyverse corresponding to the
52
59
  # given original object.
@@ -59,23 +66,35 @@ module Rubyverse
59
66
  # return it.
60
67
  #
61
68
  # @param original The original object.
62
- def rubyverse_new (original); original; end
63
-
64
- end
69
+ # @abstract You MUST supply your own implementation.
70
+ def rubyverse_new (original); end
71
+ remove_method :rubyverse_new # API doc only
65
72
 
66
- # Extends the Object class to support Rubyverses.
67
- class Object
68
-
69
- # Return the map of Rubyverses to parallel objects.
73
+ # Return the map of original-to-#rubyversed objects.
70
74
  #
71
- # @param create [Boolean] Whether to create the map if it doesn't exist.
75
+ # @param create [Boolean] Whether to create the map if it doesn't
76
+ # exist yet.
72
77
  # @return [Hash]
73
78
  def rubyverse_map (create = true)
74
- if create then @rubyverse_map ||= {}
79
+ if create then @rubyverse_map ||= {}.compare_by_identity
75
80
  else @rubyverse_map
76
81
  end
77
82
  end
78
83
 
84
+ # Return an object's parallel object in this Rubyverse.
85
+ #
86
+ # Required by {Object#in_rubyverse}.
87
+ #
88
+ # @param object The original object.
89
+ def rubyversed (object)
90
+ self.rubyverse_map[object] ||= rubyverse_new object
91
+ end
92
+
93
+ end
94
+
95
+ # Extends the Object class to support Rubyverses.
96
+ class Object
97
+
79
98
  # Return ourselves, the original Rubyverse object.
80
99
  #
81
100
  # Parallel object classes should override this method.
@@ -83,10 +102,17 @@ class Object
83
102
 
84
103
  # Return this object's parallel object in another Rubyverse.
85
104
  #
105
+ # This is a helper method to obtain the {Rubyverse#rubyversed}
106
+ # object for an intermediate result in a method call chain.
107
+ #
108
+ # # Three ways to invoke #something on "other" in Rubyverse "rubyverse"
109
+ # # and then invoke #another on the result in Rubyverse "rubyverse":
110
+ # rubyverse.rubyversed(other).something.in_rubyverse(rubyverse).another
111
+ # other.in_rubyverse(rubyverse).something.in_rubyverse(rubyverse).another
112
+ # rubyverse.rubyversed(rubyverse.rubyversed(other).something).another
113
+ #
86
114
  # @param rubyverse [Rubyverse] The desired Rubyverse.
87
- def in_rubyverse (rubyverse)
88
- rubyverse_map[rubyverse] ||= rubyverse.rubyverse_new self
89
- end
115
+ def in_rubyverse (rubyverse); rubyverse.rubyversed self; end
90
116
 
91
117
  end
92
118
 
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rubyverse"
3
- s.version = "0.0.1"
4
- s.date = "2014-04-13"
3
+ s.version = "1.0.0"
4
+ s.date = "2014-04-25"
5
5
  s.authors = ["Brian Katzung"]
6
6
  s.email = ["briank@kappacs.com"]
7
7
  s.homepage = "http://rubygems.org/gems/rubyverse"
metadata CHANGED
@@ -3,10 +3,10 @@ name: rubyverse
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brian Katzung
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2014-04-13 00:00:00 -05:00
17
+ date: 2014-04-25 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20