mostash 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mostash/mostash.rb +2 -1
- data/spec/as_hash_spec.rb +15 -0
- metadata +5 -10
- data/.gitignore +0 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/mostash/mostash.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Mostash < OpenStruct
|
2
2
|
def initialize(init={})
|
3
3
|
super({})
|
4
|
+
@initial_hash = init
|
4
5
|
__init__ init
|
5
6
|
end
|
6
7
|
|
@@ -11,7 +12,7 @@ class Mostash < OpenStruct
|
|
11
12
|
elsif __is_setter__( method_name )
|
12
13
|
super method_name, __adjusted_value__( args.first )
|
13
14
|
else
|
14
|
-
super
|
15
|
+
super || @initial_hash.send(:[], method_name, *args, &block)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
data/spec/as_hash_spec.rb
CHANGED
@@ -16,6 +16,21 @@ describe 'MoStash as Hash' do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
context 'initialization' do
|
20
|
+
it "should support initialzation from hash with default value" do
|
21
|
+
mo = Mostash.new(Hash.new(123))
|
22
|
+
|
23
|
+
mo.doesnt_exist.should == 123
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should support initialization from hash with block for deafult" do
|
27
|
+
h = Hash.new { |hash, key| hash[key] = "Go Fish: #{key}" }
|
28
|
+
mo = Mostash.new h
|
29
|
+
|
30
|
+
mo.doesnt_exist.should == "Go Fish: doesnt_exist"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
19
34
|
context 'hash functions' do
|
20
35
|
|
21
36
|
it "should respond to empty?" do
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mostash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Joel Friedman
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-04-18 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -41,7 +39,6 @@ extensions: []
|
|
41
39
|
extra_rdoc_files:
|
42
40
|
- README.markdown
|
43
41
|
files:
|
44
|
-
- .gitignore
|
45
42
|
- README.markdown
|
46
43
|
- Rakefile
|
47
44
|
- VERSION
|
@@ -55,8 +52,8 @@ homepage:
|
|
55
52
|
licenses: []
|
56
53
|
|
57
54
|
post_install_message:
|
58
|
-
rdoc_options:
|
59
|
-
|
55
|
+
rdoc_options: []
|
56
|
+
|
60
57
|
require_paths:
|
61
58
|
- lib
|
62
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -64,7 +61,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
61
|
requirements:
|
65
62
|
- - ">="
|
66
63
|
- !ruby/object:Gem::Version
|
67
|
-
hash: 3
|
68
64
|
segments:
|
69
65
|
- 0
|
70
66
|
version: "0"
|
@@ -73,7 +69,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
69
|
requirements:
|
74
70
|
- - ">="
|
75
71
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
72
|
segments:
|
78
73
|
- 0
|
79
74
|
version: "0"
|
data/.gitignore
DELETED