hamster 0.3.4 → 0.3.5

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.
@@ -1,3 +1,7 @@
1
+ === 0.3.5 / 2010-05-03
2
+
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
+
1
5
  === 0.3.4 / 2010-04-29
2
6
 
3
7
  * Reduce garbage collection by keeping a singleton instance of an empty hash.
@@ -1,6 +1,6 @@
1
1
  = Hamster - Efficient, Immutable, Thread-Safe Collection classes for Ruby
2
2
 
3
- GitHub: http://github.com/harukizaemon/bundler
3
+ GitHub: http://github.com/harukizaemon/hamster
4
4
  Gemcutter: http://gemcutter/gems/hamster
5
5
  email: haruki.zaemon@gmail.com
6
6
  IRC: #haruki_zaemon on freenode
@@ -1,6 +1,7 @@
1
1
  require 'forwardable'
2
2
 
3
3
  require 'hamster/immutable'
4
+ require 'hamster/undefined'
4
5
  require 'hamster/trie'
5
6
 
6
7
  module Hamster
@@ -42,7 +43,8 @@ module Hamster
42
43
  end
43
44
  def_delegator :self, :get, :[]
44
45
 
45
- def put(key, value)
46
+ def put(key, value = Undefined)
47
+ return put(key, yield(key, get(key))) if value.equal?(Undefined)
46
48
  transform { @trie = @trie.put(key, value) }
47
49
  end
48
50
 
@@ -1,5 +1,5 @@
1
1
  module Hamster
2
2
 
3
- VERSION = "0.3.4".freeze
3
+ VERSION = "0.3.5".freeze
4
4
 
5
5
  end
@@ -10,6 +10,23 @@ describe Hamster::Hash do
10
10
  @original = Hamster.hash("A" => "aye", "B" => "bee", "C" => "see")
11
11
  end
12
12
 
13
+ describe "with a block" do
14
+
15
+ it "passes the key to the block" do
16
+ @original.put("A") { |key, value| key.should == "A" }
17
+ end
18
+
19
+ it "passes the value to the block" do
20
+ @original.put("A") { |key, value| value.should == "aye" }
21
+ end
22
+
23
+ it "replaces the value with the result of the block" do
24
+ result = @original.put("A") { |key, value| "FLIBBLE" }
25
+ result.get("A").should == "FLIBBLE"
26
+ end
27
+
28
+ end
29
+
13
30
  describe "with a unique key" do
14
31
 
15
32
  before do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 4
9
- version: 0.3.4
8
+ - 5
9
+ version: 0.3.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Simon Harris
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-29 00:00:00 +10:00
17
+ date: 2010-05-03 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency