sonofhash 0.1 → 0.11
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.
- data/README.md +18 -0
- data/lib/sonofhash.rb +22 -0
- metadata +3 -2
data/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Quacks like a Hash, but contains one additional method - commit()
|
|
2
|
+
|
|
3
|
+
Typical usage:
|
|
4
|
+
|
|
5
|
+
require 'rubygems'
|
|
6
|
+
require 'sonofhash'
|
|
7
|
+
|
|
8
|
+
parent = SonOfHash.new
|
|
9
|
+
child = parent.new_child
|
|
10
|
+
|
|
11
|
+
parent['name'] = 'Moondublin'
|
|
12
|
+
puts child['name'] # Moondublin
|
|
13
|
+
|
|
14
|
+
child['name'] = 'Lugrat'
|
|
15
|
+
puts parent['name'] # Moondublin
|
|
16
|
+
|
|
17
|
+
child.commit
|
|
18
|
+
puts parent['name'] # Lugrat
|
data/lib/sonofhash.rb
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
require 'set'
|
|
2
2
|
|
|
3
|
+
# Quacks like a Hash, but contains one additional method - commit()
|
|
4
|
+
#
|
|
5
|
+
# Typical usage:
|
|
6
|
+
#
|
|
7
|
+
# require 'rubygems'
|
|
8
|
+
# require 'sonofhash'
|
|
9
|
+
#
|
|
10
|
+
# parent = SonOfHash.new
|
|
11
|
+
# child = parent.new_child
|
|
12
|
+
#
|
|
13
|
+
# parent['name'] = 'Moondublin'
|
|
14
|
+
# puts child['name'] # Moondublin
|
|
15
|
+
#
|
|
16
|
+
# child['name'] = 'Lugrat'
|
|
17
|
+
# puts parent['name'] # Moondublin
|
|
18
|
+
#
|
|
19
|
+
# child.commit
|
|
20
|
+
# puts parent['name'] # Lugrat
|
|
21
|
+
#
|
|
3
22
|
class SonOfHash
|
|
4
23
|
|
|
5
24
|
def initialize(parent={})
|
|
@@ -8,6 +27,8 @@ class SonOfHash
|
|
|
8
27
|
@parent = parent
|
|
9
28
|
end
|
|
10
29
|
|
|
30
|
+
# Create a new child of this object. This is the primary way to
|
|
31
|
+
# record changes.
|
|
11
32
|
def new_child
|
|
12
33
|
return SonOfHash.new(self)
|
|
13
34
|
end
|
|
@@ -36,6 +57,7 @@ class SonOfHash
|
|
|
36
57
|
return @store.delete(key)
|
|
37
58
|
end
|
|
38
59
|
|
|
60
|
+
# Merges the changes of this object into its parent
|
|
39
61
|
def commit
|
|
40
62
|
@store.each {|key, value| @parent[key] = value}
|
|
41
63
|
@deletions.each {|key| @parent.delete(key)}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sonofhash
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: "0.
|
|
4
|
+
version: "0.11"
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tushar Pokle
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2010-03-
|
|
12
|
+
date: 2010-03-12 00:00:00 +11:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -23,6 +23,7 @@ extra_rdoc_files: []
|
|
|
23
23
|
|
|
24
24
|
files:
|
|
25
25
|
- lib/sonofhash.rb
|
|
26
|
+
- README.md
|
|
26
27
|
has_rdoc: true
|
|
27
28
|
homepage: http://gemcutter.org/gems/partition
|
|
28
29
|
licenses: []
|