hashery 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.ruby +30 -17
  2. data/.yardopts +1 -0
  3. data/Config.rb +28 -0
  4. data/{QED.rdoc → DEMO.rdoc} +0 -0
  5. data/HISTORY.rdoc +37 -0
  6. data/LICENSE.txt +26 -0
  7. data/NOTICE.txt +46 -0
  8. data/README.rdoc +10 -7
  9. data/lib/hashery.rb +6 -6
  10. data/lib/hashery.yml +30 -17
  11. data/lib/hashery/association.rb +169 -109
  12. data/lib/hashery/casting_hash.rb +128 -135
  13. data/lib/hashery/core_ext.rb +89 -61
  14. data/lib/hashery/crud_hash.rb +365 -0
  15. data/lib/hashery/dictionary.rb +545 -345
  16. data/lib/hashery/fuzzy_hash.rb +177 -125
  17. data/lib/hashery/ini_hash.rb +321 -0
  18. data/lib/hashery/key_hash.rb +54 -179
  19. data/lib/hashery/linked_list.rb +245 -191
  20. data/lib/hashery/lru_hash.rb +292 -202
  21. data/lib/hashery/open_cascade.rb +133 -78
  22. data/lib/hashery/open_hash.rb +127 -61
  23. data/lib/hashery/ordered_hash.rb +128 -122
  24. data/lib/hashery/path_hash.rb +238 -0
  25. data/lib/hashery/property_hash.rb +144 -80
  26. data/lib/hashery/query_hash.rb +85 -29
  27. data/lib/hashery/stash.rb +7 -3
  28. data/lib/hashery/static_hash.rb +46 -41
  29. data/test/case_association.rb +65 -4
  30. data/test/case_dictionary.rb +149 -5
  31. data/test/{case_keyhash.rb → case_key_hash.rb} +20 -14
  32. data/test/case_lru_hash.rb +162 -0
  33. data/test/{case_opencascade.rb → case_open_cascade.rb} +4 -8
  34. data/test/case_open_hash.rb +87 -0
  35. data/test/case_query_hash.rb +226 -0
  36. data/test/helper.rb +8 -0
  37. metadata +33 -63
  38. data/COPYING.rdoc +0 -45
  39. data/lib/hashery/basic_object.rb +0 -74
  40. data/lib/hashery/basic_struct.rb +0 -288
  41. data/lib/hashery/basicobject.rb +0 -1
  42. data/lib/hashery/basicstruct.rb +0 -1
  43. data/lib/hashery/castinghash.rb +0 -1
  44. data/lib/hashery/fuzzyhash.rb +0 -1
  45. data/lib/hashery/ini.rb +0 -268
  46. data/lib/hashery/keyhash.rb +0 -1
  47. data/lib/hashery/linkedlist.rb +0 -1
  48. data/lib/hashery/lruhash.rb +0 -1
  49. data/lib/hashery/memoizer.rb +0 -64
  50. data/lib/hashery/open_object.rb +0 -1
  51. data/lib/hashery/opencascade.rb +0 -1
  52. data/lib/hashery/openhash.rb +0 -1
  53. data/lib/hashery/openobject.rb +0 -1
  54. data/lib/hashery/orderedhash.rb +0 -1
  55. data/lib/hashery/ostructable.rb +0 -186
  56. data/lib/hashery/propertyhash.rb +0 -1
  57. data/lib/hashery/queryhash.rb +0 -1
  58. data/lib/hashery/statichash.rb +0 -1
  59. data/qed/01_openhash.rdoc +0 -57
  60. data/qed/02_queryhash.rdoc +0 -21
  61. data/qed/03_castinghash.rdoc +0 -13
  62. data/qed/04_statichash.rdoc +0 -22
  63. data/qed/05_association.rdoc +0 -59
  64. data/qed/06_opencascade.rdoc +0 -58
  65. data/qed/07_fuzzyhash.rdoc +0 -141
  66. data/qed/08_properyhash.rdoc +0 -38
  67. data/qed/09_ostructable.rdoc +0 -56
  68. data/qed/applique/ae.rb +0 -1
  69. data/test/case_basicstruct.rb +0 -192
  70. data/test/case_openhash.rb +0 -22
data/.ruby CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  source:
3
- - var
3
+ - meta
4
4
  authors:
5
5
  - name: Trans
6
6
  email: transfire@gmail.com
@@ -14,10 +14,7 @@ copyrights:
14
14
  - holder: Rubyworks
15
15
  year: '2010'
16
16
  license: BSD-2-Clause
17
- replacements: []
18
- alternatives: []
19
17
  requirements:
20
- - name: blankslate
21
18
  - name: detroit
22
19
  groups:
23
20
  - build
@@ -31,33 +28,49 @@ requirements:
31
28
  - test
32
29
  development: true
33
30
  dependencies: []
31
+ alternatives: []
34
32
  conflicts: []
35
33
  repositories:
36
34
  - uri: git://github.com/rubyworks/hashery.git
37
35
  scm: git
38
36
  name: upstream
39
37
  resources:
40
- home: http://rubyworks.github.com/hashery
41
- code: http://github.com/rubyworks/hashery
42
- mail: http://groups.google.com/group/rubyworks-mailinglist
43
- docs: http://rubydocs.info/gems/hashery/frames
44
- wiki: http://wiki.github.com/rubyworks/hashery
45
- gems: http://rubygems.org/gems/hashery
38
+ - uri: http://rubyworks.github.com/hashery
39
+ label: Website
40
+ type: home
41
+ - uri: http://github.com/rubyworks/hashery
42
+ label: Source Code
43
+ type: code
44
+ - uri: http://groups.google.com/group/rubyworks-mailinglist
45
+ label: Mailing List
46
+ type: mail
47
+ - uri: http://rubydoc.info/github/rubyworks/hashery/master/frames
48
+ label: Documentation
49
+ type: docs
50
+ - uri: http://wiki.github.com/rubyworks/hashery
51
+ label: User Guide
52
+ type: wiki
53
+ - uri: http://rubygems.org/gems/hashery
54
+ type: gems
55
+ categories: []
46
56
  extra: {}
47
57
  load_path:
48
58
  - lib
59
+ - alt
49
60
  revision: 0
50
61
  created: '2010-04-21'
51
62
  summary: Facets-bread collection of Hash-like classes.
52
63
  title: Hashery
53
- version: 1.5.0
64
+ version: 2.0.0
54
65
  name: hashery
55
- description: ! 'The Hashery is a collection of Hash-like classes, spun-off from the
56
- original
66
+ description: ! 'The Hashery is a tight collection of Hash-like classes. Included among
67
+ its many
68
+
69
+ offerings are the auto-sorting Dictionary class, the efficient LRUHash, the
57
70
 
58
- Ruby Facets library. Included are the widely used OrderedHash, the related but
71
+ flexible OpenHash and the convenient KeyHash. Nearly every class is a subclass
59
72
 
60
- more featured Dictionary class, a number of open classes, similiar to the
73
+ of the CRUDHash which defines a CRUD model on top of Ruby''s standard Hash
61
74
 
62
- standard OpenStruct and a few variations on the standard Hash.'
63
- date: '2011-11-10'
75
+ making it a snap to subclass and augment to fit any specific use case.'
76
+ date: '2012-06-18'
data/.yardopts CHANGED
@@ -1,3 +1,4 @@
1
+ --plugin tomdoc
1
2
  --output-dir doc
2
3
  --title Hashery
3
4
  --protected
@@ -0,0 +1,28 @@
1
+ config 'rubytest' do
2
+ $:.unshift 'test'
3
+ $:.unshift 'lib'
4
+ end
5
+
6
+ profile 'coverage' do
7
+ config 'rubytest' do
8
+ $:.unshift 'test'
9
+ $:.unshift 'lib'
10
+
11
+ require 'simplecov'
12
+ SimpleCov.command_name 'RubyTest'
13
+ SimpleCov.start do
14
+ add_filter '/test/'
15
+ add_filter '/lib/hashery/ordered_hash.rb'
16
+ coverage_dir 'log/coverage'
17
+ end
18
+ end
19
+
20
+ config 'qed' do
21
+ require 'simplecov'
22
+ SimpleCov.command_name 'QED'
23
+ SimpleCov.start do
24
+ add_filter '/demo/'
25
+ coverage_dir 'log/coverage'
26
+ end
27
+ end
28
+ end
File without changes
@@ -1,5 +1,42 @@
1
1
  = RELEASE HISTORY
2
2
 
3
+ == 2.0.0 / 2012-05-11
4
+
5
+ This is a big release for Hashery which both culls some of it's
6
+ less fitting classes and modules while greatly improving the rest.
7
+ The first and most immediate change is use of a proper namespace.
8
+ All classes and modules are now appropriately kept in the `Hashery`
9
+ namespace. To get the old behavior you can `include Hashery` as the
10
+ toplevel. For the other changes and improvements dive into the
11
+ API documentation.
12
+
13
+ Changes:
14
+
15
+ * Use proper Hashery namespace.
16
+ * Add CRUDHash, which also serves a good base class.
17
+ * Improved OpenHash to be nearly 100% open.
18
+ * Deprecate BasicStruct, as it would be better to improve OpenStruct.
19
+ * Deprecate BasicCascade, though it never really came to be.
20
+ * Deprecate BasicObject emulator, as it is no longer needed.
21
+ * Deprecate Memoizer, not sure how that got in here anyway.
22
+ * Deprecate Ostructable, which can be paired up with better OpenStruct.
23
+ * Removed open_object.rb, which has long been deprecated.
24
+
25
+
26
+ == 1.5.1 / 2012-05-09
27
+
28
+ This release adds transformative #each method to OpenCascade, to
29
+ ensure #each returns an OpenCascade. Also, BasicCascade has been
30
+ added that is like OpenCascade by fully open by use of BasicObject
31
+ as a base class.
32
+
33
+ Changes:
34
+
35
+ * Fix OpenCascade#each (porecreat).
36
+ * Introduce BasicCascade class.
37
+ * Renamed `Ini` class to `IniHash` class.
38
+
39
+
3
40
  == 1.5.0 / 2011-11-10
4
41
 
5
42
  In this release, CoreExt module has been addeed to encapsulate
@@ -0,0 +1,26 @@
1
+ Hashery
2
+
3
+ Copyright (c) 2009 Rubyworks
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ this software and associated documentation files (the "Software"), to deal in
9
+ the Software without restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11
+ Software, and to permit persons to whom the Software is furnished to do so,
12
+ subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ Website: http://rubyworks.github.com/hashery
25
+ License: http://www.spdx.org/licenses/MIT
26
+
@@ -0,0 +1,46 @@
1
+ All copyright holders have released their wares with a compatible
2
+ license or have given permission for their work to be distributed
3
+ under the same license as Hashery.
4
+
5
+ BasicObject is based on Jim Weirich's BlankSlate class.
6
+
7
+ BlankSlate
8
+ Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
9
+ All rights reserved.
10
+
11
+ Dictionary is based on OrderedHash by Jan Molic.
12
+
13
+ OrderHash 2.0 Copyright (c) 2005 Jan Molic.
14
+
15
+
16
+ LRUHash is based on same by Robert Klemme
17
+
18
+ Copyright (c) 2010 Robert Klemme
19
+
20
+
21
+ Memoizer is based on same by Erik Veenstra
22
+
23
+ Copyright (c) 2006 Erik Veenstra
24
+
25
+
26
+ IniHash is based on Ini library by Jeena Paradies
27
+
28
+ Copyright (c) 2007 Jeena Paradies <info@jeenaparadies.net>
29
+
30
+
31
+ LinkedList is based on same by Kirk Haines
32
+
33
+ Copyright (C) 2006 Kirk Haines <khaines@enigo.com>
34
+
35
+
36
+ FuzzyHash is based on the same by Joshua Hull.
37
+
38
+ Copyright (c) 2009 Joshua Hull
39
+
40
+
41
+ PathHash is based on SlashedHash by Daniel Parker
42
+
43
+ HashMagic by Daniel Parker <gems@behindlogic.com>
44
+ Copyright (c) 2006 BehindLogic
45
+ http://hash_magic.rubyforge.org
46
+
@@ -66,19 +66,22 @@ Well git in there!
66
66
 
67
67
  Hashery uses QED[http://rubyworks.github.com/qed] and
68
68
  Lemon[http://rubyworks.github.com/lemon] test frameworks.
69
- Both are used in nearly the same fashion:
69
+ The QED framework to create well tested high-level documentation.
70
+ Run the QED specs via:
70
71
 
71
- $ qed -Ilib qed/
72
+ $ qed -Ilib demo/
72
73
 
73
- And
74
+ Lemon is used to create low-level unit tests. Run these via the
75
+ RubyTest univeral test harness.
76
+
77
+ $ rubytest -Ilib test/
74
78
 
75
- $ lemon -Ilib test/
76
79
 
77
80
  === Patches
78
81
 
79
82
  Hashery's repository is hosted on GitHub[http://github.com/rubyworks/hashery].
80
- If you'd like to offer up a fix or feature change then fork the repo and
81
- submit a pull request (preferably in a topic branch). I assume you have heard
83
+ If you'd like to offer up a fix or feature, fork the repo and submit a pull
84
+ request (preferably in a topic branch). I assume you have heard
82
85
  all the talk about proper {practices}[http://learn.github.com/p/intro.html],
83
86
  so I won't bug you with it yet again.
84
87
 
@@ -100,5 +103,5 @@ See COPYING.rdoc file for further details.
100
103
 
101
104
  Some libraries included in the Hashery have special copyrights
102
105
  attributing specific authors. Please see each library script for
103
- specifics.
106
+ specifics and the NOITCE.txt file for an overview.
104
107
 
@@ -1,20 +1,20 @@
1
1
  require 'hashery/core_ext'
2
2
 
3
- require 'hashery/basic_struct'
3
+ #require 'hashery/basic_struct'
4
4
  require 'hashery/casting_hash'
5
+ require 'hashery/crud_hash'
5
6
  require 'hashery/dictionary'
6
7
  require 'hashery/fuzzy_hash'
8
+ require 'hashery/ini_hash'
7
9
  require 'hashery/linked_list'
8
10
  require 'hashery/lru_hash'
9
11
  require 'hashery/key_hash'
10
- require 'hashery/memoizer'
11
12
  require 'hashery/open_cascade'
12
13
  require 'hashery/open_hash'
13
- #require 'hashery/open_object'
14
- require 'hashery/ordered_hash'
15
- require 'hashery/ostructable'
14
+ #require 'hashery/ordered_hash'
15
+ #require 'hashery/ostructable'
16
16
  require 'hashery/property_hash'
17
17
  require 'hashery/query_hash'
18
18
  require 'hashery/static_hash'
19
19
 
20
- #require 'hashery/ini'
20
+
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  source:
3
- - var
3
+ - meta
4
4
  authors:
5
5
  - name: Trans
6
6
  email: transfire@gmail.com
@@ -14,10 +14,7 @@ copyrights:
14
14
  - holder: Rubyworks
15
15
  year: '2010'
16
16
  license: BSD-2-Clause
17
- replacements: []
18
- alternatives: []
19
17
  requirements:
20
- - name: blankslate
21
18
  - name: detroit
22
19
  groups:
23
20
  - build
@@ -31,33 +28,49 @@ requirements:
31
28
  - test
32
29
  development: true
33
30
  dependencies: []
31
+ alternatives: []
34
32
  conflicts: []
35
33
  repositories:
36
34
  - uri: git://github.com/rubyworks/hashery.git
37
35
  scm: git
38
36
  name: upstream
39
37
  resources:
40
- home: http://rubyworks.github.com/hashery
41
- code: http://github.com/rubyworks/hashery
42
- mail: http://groups.google.com/group/rubyworks-mailinglist
43
- docs: http://rubydocs.info/gems/hashery/frames
44
- wiki: http://wiki.github.com/rubyworks/hashery
45
- gems: http://rubygems.org/gems/hashery
38
+ - uri: http://rubyworks.github.com/hashery
39
+ label: Website
40
+ type: home
41
+ - uri: http://github.com/rubyworks/hashery
42
+ label: Source Code
43
+ type: code
44
+ - uri: http://groups.google.com/group/rubyworks-mailinglist
45
+ label: Mailing List
46
+ type: mail
47
+ - uri: http://rubydoc.info/github/rubyworks/hashery/master/frames
48
+ label: Documentation
49
+ type: docs
50
+ - uri: http://wiki.github.com/rubyworks/hashery
51
+ label: User Guide
52
+ type: wiki
53
+ - uri: http://rubygems.org/gems/hashery
54
+ type: gems
55
+ categories: []
46
56
  extra: {}
47
57
  load_path:
48
58
  - lib
59
+ - alt
49
60
  revision: 0
50
61
  created: '2010-04-21'
51
62
  summary: Facets-bread collection of Hash-like classes.
52
63
  title: Hashery
53
- version: 1.5.0
64
+ version: 2.0.0
54
65
  name: hashery
55
- description: ! 'The Hashery is a collection of Hash-like classes, spun-off from the
56
- original
66
+ description: ! 'The Hashery is a tight collection of Hash-like classes. Included among
67
+ its many
68
+
69
+ offerings are the auto-sorting Dictionary class, the efficient LRUHash, the
57
70
 
58
- Ruby Facets library. Included are the widely used OrderedHash, the related but
71
+ flexible OpenHash and the convenient KeyHash. Nearly every class is a subclass
59
72
 
60
- more featured Dictionary class, a number of open classes, similiar to the
73
+ of the CRUDHash which defines a CRUD model on top of Ruby''s standard Hash
61
74
 
62
- standard OpenStruct and a few variations on the standard Hash.'
63
- date: '2011-11-10'
75
+ making it a snap to subclass and augment to fit any specific use case.'
76
+ date: '2012-06-18'
@@ -1,123 +1,183 @@
1
- # Copyright (c) 2005 Thomas Sawyer
1
+ module Hashery
2
2
 
3
- # = Association
4
- #
5
- # General binary association allows one object to be
6
- # associated with another. It has a variety of uses,
7
- # link-lists, simple ordered maps and mixed collections,
8
- # among them.
9
- #
10
- # NOTE: This class is still fairly experimental. And it is not
11
- # loaded along with the other Hashery libraries when using
12
- # `require 'hashery'`.
13
- #
14
- # == Usage
15
- #
16
- # Associations can be used to draw simple relationships.
17
- #
18
- # :Apple >> :Fruit
19
- # :Apple >> :Red
20
- #
21
- # :Apple.associations #=> [ :Fruit, :Red ]
22
- #
23
- # It can also be used for simple lists of ordered pairs.
24
- #
25
- # c = [ :a >> 1, :b >> 2 ]
26
- # c.each { |k,v| puts "#{k} associated with #{v} }
27
- #
28
- # produces
29
- #
30
- # a associated with 1
31
- # b associated with 2
32
- #
33
- # == Limitations
34
- #
35
- # The method :>> is used to construct the association.
36
- # It is a rarely used method so it is generally available.
37
- # But you can't use it for any of the following classes
38
- # becuase they use #>> for other things.
39
- #
40
- # Bignum
41
- # Fixnum
42
- # Date
43
- # IPAddr
44
- # Process::Status
45
- #
46
- #--
47
- # TODO: Should associations be singleton?
48
- #
49
- # TODO: Is it really wise to keep a table of all associations?
50
- #++
51
-
52
- class Association
53
- include Comparable
3
+ # TODO: Should associations be singleton?
4
+ #
5
+ # TODO: Is it really wise to keep a table of all associations?
54
6
 
55
- class << self
56
- # Store association references.
57
- def reference
58
- @reference ||= Hash.new{ |h,k,v| h[k]=[] }
7
+ # Association is a general binary association that allows one
8
+ # object to be associated with another. It has a variety of uses,
9
+ # such as linked-lists, simple ordered maps and mixed collections,
10
+ # among them.
11
+ #
12
+ # NOTE: This class is still fairly experimental. And it is not
13
+ # loaded along with the other Hashery libraries when using
14
+ # `require 'hashery'`. It must be required independently.
15
+ #
16
+ # Associations can be used to draw simple relationships.
17
+ #
18
+ # :Apple >> :Fruit
19
+ # :Apple >> :Red
20
+ #
21
+ # :Apple.associations #=> [ :Fruit, :Red ]
22
+ #
23
+ # It can also be used for simple lists of ordered pairs.
24
+ #
25
+ # c = [ :a >> 1, :b >> 2 ]
26
+ # c.each { |k,v| puts "#{k} associated with #{v} }
27
+ #
28
+ # produces
29
+ #
30
+ # a associated with 1
31
+ # b associated with 2
32
+ #
33
+ # The method :>> is used to construct the association.
34
+ # It is a rarely used method so it is generally available.
35
+ # But you can't use it for any of the following classes
36
+ # becuase they use #>> for other things.
37
+ #
38
+ # Bignum
39
+ # Fixnum
40
+ # Date
41
+ # IPAddr
42
+ # Process::Status
43
+ #
44
+ class Association
45
+ include Comparable
46
+
47
+ class << self
48
+ #
49
+ # Store association references.
50
+ #
51
+ # Returns `Hash` of all associaitons.
52
+ #
53
+ def reference
54
+ @reference ||= Hash.new{ |h,k,v| h[k]=[] }
55
+ end
56
+
57
+ #
58
+ # Shortcut for #new.
59
+ #
60
+ # index - The "index key" of the association.
61
+ # value - The "value" of the association.
62
+ #
63
+ # Returns `Association`.
64
+ #
65
+ def [](index, value)
66
+ new(index, value)
67
+ end
68
+
69
+ #def new(index, value)
70
+ # lookup[[index, value]] ||= new(index, value)
71
+ #end
72
+
73
+ #def lookup
74
+ # @lookup ||= {}
75
+ #end
59
76
  end
60
77
 
61
- def [](index, value)
62
- new(index, value)
78
+ #
79
+ # The "index key" of the association.
80
+ #
81
+ attr_accessor :index
82
+
83
+ #
84
+ # The "value" of the association.
85
+ #
86
+ attr_accessor :value
87
+
88
+ #
89
+ # Initialize new Association.
90
+ #
91
+ # index - The "index key" of the association.
92
+ # value - The "value" of the association.
93
+ #
94
+ def initialize(index, value=nil)
95
+ @index = index
96
+ @value = value
97
+
98
+ unless index.associations.include?(value)
99
+ index.associations << value
100
+ end
63
101
  end
64
102
 
65
- #def new(index, value)
66
- # lookup[[index, value]] ||= new(index, value)
67
- #end
68
-
69
- #def lookup
70
- # @lookup ||= {}
71
- #end
72
- end
73
-
74
- attr_accessor :index
75
- attr_accessor :value
76
-
77
- def initialize(index, value=nil)
78
- @index = index
79
- @value = value
80
-
81
- unless index.associations.include?(value)
82
- index.associations << value
103
+ #
104
+ # Compare the values of two associations.
105
+ #
106
+ # TODO: Comparions with non-associations?
107
+ #
108
+ # assoc - The other `Association`.
109
+ #
110
+ # Returns [Integer] `1`, `0`, or `-1`.
111
+ #
112
+ def <=>(assoc)
113
+ return -1 if self.value < assoc.value
114
+ return 1 if self.value > assoc.value
115
+ return 0 if self.value == assoc.value
83
116
  end
84
- end
85
-
86
- def <=>(assoc)
87
- return -1 if self.value < assoc.value
88
- return 1 if self.value > assoc.value
89
- return 0 if self.value == assoc.value
90
- end
91
117
 
92
- def invert!
93
- temp = @index
94
- @index = @value
95
- @value = temp
96
- end
97
-
98
- def to_s
99
- return "#{index.to_s}#{value.to_s}"
100
- end
101
-
102
- def inspect
103
- %{#{@index.inspect} >> #{@value.inspect}}
104
- end
118
+ #
119
+ # Invert association, making the index the value and vice-versa.
120
+ #
121
+ # Returns [Array] with two-elements reversed.
122
+ #
123
+ def invert!
124
+ temp = @index
125
+ @index = @value
126
+ @value = temp
127
+ end
105
128
 
106
- def to_ary
107
- [ @index, @value ]
108
- end
129
+ #
130
+ # Produce a string representation.
131
+ #
132
+ # Returns [String].
133
+ #
134
+ def to_s
135
+ return "#{index} >> #{value}"
136
+ end
109
137
 
110
- # Object extensions.
111
- #
112
- module Kernel
138
+ #
139
+ # Produce a literal code string for creating an association.
140
+ #
141
+ # Returns [String].
142
+ #
143
+ def inspect
144
+ "#{index.inspect} >> #{value.inspect}"
145
+ end
113
146
 
114
- # Define an association with +self+.
115
- def >>(to)
116
- Association.new(self, to)
147
+ #
148
+ # Convert to two-element associative array.
149
+ #
150
+ # Returns [Array] Two-element Array of index and value pair.
151
+ #
152
+ def to_ary
153
+ [index, value]
117
154
  end
118
155
 
119
- def associations
120
- Association.reference[self]
156
+ #
157
+ # Object extensions.
158
+ #
159
+ module Kernel
160
+
161
+ #
162
+ # Define an association for +self+.
163
+ #
164
+ # to - The value of the association.
165
+ #
166
+ # Returns [Association].
167
+ #
168
+ def >>(to)
169
+ Association.new(self, to)
170
+ end
171
+
172
+ #
173
+ # List of associations for this object.
174
+ #
175
+ # Returns an `Array` of `Associations`.
176
+ #
177
+ def associations
178
+ Association.reference[self]
179
+ end
180
+
121
181
  end
122
182
 
123
183
  end
@@ -125,10 +185,9 @@ class Association
125
185
  end
126
186
 
127
187
  class Object #:nodoc:
128
- include Association::Kernel
188
+ include Hashery::Association::Kernel
129
189
  end
130
190
 
131
-
132
191
  #--
133
192
  # Setup the >> method in classes that use it already.
134
193
  #
@@ -160,3 +219,4 @@ end
160
219
  # end
161
220
  #++
162
221
 
222
+ # Copyright (c) 2005 Rubyworks, Thomas Sawyer