GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Mash is a Hash with the ability to read, write, and test for the presence of arbitrary attributes using method calls.
Clone URL: git://github.com/mbleigh/mash.git
Mash#initialize should accept a default block
judofyr (author)
Tue Jul 22 06:44:46 -0700 2008
commit  e7bd3ecb863ecbabc56b161e78277661edb1b85e
tree    21c6acbed9fa8140636d4af301326b84d0f67e26
parent  c566221b441c256c64024227b16ac44650dc8fa8
...
44
45
46
47
 
48
49
 
50
51
52
...
65
66
67
68
 
69
70
71
...
174
175
176
177
 
178
179
180
...
44
45
46
 
47
48
 
49
50
51
52
...
65
66
67
 
68
69
70
71
...
174
175
176
 
177
178
179
180
0
@@ -44,9 +44,9 @@ class Mash < Hash
0
   # convert it to a Mash including recursively
0
   # descending into arrays and hashes, converting
0
   # them as well.
0
- def initialize(source_hash = nil)
0
+ def initialize(source_hash = nil, &blk)
0
     deep_update(source_hash) if source_hash
0
- super(nil)
0
+ super(&blk)
0
   end
0
   
0
   def id #:nodoc:
0
@@ -65,7 +65,7 @@ class Mash < Hash
0
     if key.is_a?(Symbol) && key?(key)
0
       self[key]
0
     else
0
- super
0
+ key ? super : super()
0
     end
0
   end
0
   
0
@@ -174,7 +174,7 @@ class Mash < Hash
0
     elsif key?(method_name)
0
       self[method_name]
0
     elsif match = method_name.to_s.match(/^([a-z][a-z0-9A-Z_]+)$/)
0
- default
0
+ default(method_name)
0
     else
0
       super
0
     end
...
106
107
108
 
 
 
 
 
 
 
109
110
111
...
106
107
108
109
110
111
112
113
114
115
116
117
118
0
@@ -106,6 +106,13 @@ describe Mash do
0
       copy.address.object_id.should_not == initial.address.object_id
0
     end
0
     
0
+ it "should accept a default block" do
0
+ initial = Mash.new { |h,i| h[i] = []}
0
+ initial.default_proc.should_not be_nil
0
+ initial.default.should be_nil
0
+ initial.test.should == []
0
+ initial.test?.should be_true
0
+ end
0
   end
0
 end
0
 

Comments

    No one has commented yet.