hamster 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- === 0.3.5 / 2010-05-03
1
+ === 0.3.6 / 2010-05-03
2
2
 
3
3
  * Hash#put now supports returning a value from a block instead of passing an explicit value. Almost like a substitute for the non-functional []=
4
4
 
data/README.rdoc CHANGED
@@ -67,9 +67,16 @@ As you can see, updating the hash returned a copy leaving the original intact. S
67
67
 
68
68
  Hamster's hash doesn't provide an assignment (<tt>#[]=</tt>) method. The reason for this is simple yet irritating: Ruby assignment methods always return the assigned value, no matter what the method itself returns. For example:
69
69
 
70
- {}[:name] = "Simon" # => "Simon"
70
+ counters = Hamster.hash(:odds => 0, :evens => 0)
71
+ counters[:odds] += 1 # => 1
71
72
 
72
- Because of this, the returned copy would be lost thus making the construct useless.
73
+ Because of this, the returned copy would be lost thus making the construct useless. Instead <tt>#put</tt> accepts a block instead of an explicit value so we can still do something similar
74
+
75
+ counters.put(:odds) { |value| value + 1 } # => {:odds => 1, :evens => 0}
76
+
77
+ or more succinctly:
78
+
79
+ counters.put(:odds, &:next) # => {:odds => 1, :evens => 0}
73
80
 
74
81
  === Set
75
82
 
@@ -123,7 +130,7 @@ Besides <tt>Hamster.list</tt> there are other ways to construct lists:
123
130
 
124
131
  or even more succinctly:
125
132
 
126
- integers = Hamster.iterate(1, &:succ)
133
+ integers = Hamster.iterate(1, &:next)
127
134
 
128
135
  You also get <tt>Enumerable#to_list</tt> so you can slowly transition from built-in collection classes to Hamster.
129
136
 
data/lib/hamster/hash.rb CHANGED
@@ -44,7 +44,7 @@ module Hamster
44
44
  def_delegator :self, :get, :[]
45
45
 
46
46
  def put(key, value = Undefined)
47
- return put(key, yield(key, get(key))) if value.equal?(Undefined)
47
+ return put(key, yield(get(key))) if value.equal?(Undefined)
48
48
  transform { @trie = @trie.put(key, value) }
49
49
  end
50
50
 
@@ -1,5 +1,5 @@
1
1
  module Hamster
2
2
 
3
- VERSION = "0.3.5".freeze
3
+ VERSION = "0.3.6".freeze
4
4
 
5
5
  end
@@ -12,19 +12,20 @@ describe Hamster::Hash do
12
12
 
13
13
  describe "with a block" do
14
14
 
15
- it "passes the key to the block" do
16
- @original.put("A") { |key, value| key.should == "A" }
17
- end
18
-
19
15
  it "passes the value to the block" do
20
- @original.put("A") { |key, value| value.should == "aye" }
16
+ @original.put("A") { |value| value.should == "aye" }
21
17
  end
22
18
 
23
19
  it "replaces the value with the result of the block" do
24
- result = @original.put("A") { |key, value| "FLIBBLE" }
20
+ result = @original.put("A") { |value| "FLIBBLE" }
25
21
  result.get("A").should == "FLIBBLE"
26
22
  end
27
23
 
24
+ it "supports to_proc methods" do
25
+ result = @original.put("A", &:next)
26
+ result.get("A").should == "ayf"
27
+ end
28
+
28
29
  end
29
30
 
30
31
  describe "with a unique key" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 5
9
- version: 0.3.5
8
+ - 6
9
+ version: 0.3.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Simon Harris