diff options
author | Michael Bleigh <michael@intridea.com> | 2010-08-31 00:22:49 -0500 |
---|---|---|
committer | Michael Bleigh <michael@intridea.com> | 2010-08-31 00:22:49 -0500 |
commit | f76d4c9613206f376b1e869cf45aa56a04471e40 (patch) | |
tree | 6ded854e8d0bc2a389029bd868ff5320a19158a3 | |
parent | 18479a29ad6dacfad84ff0de75edd0c81dc74051 (diff) | |
parent | 54f9bdde2930deda2d223a00b9fb40a8d236e904 (diff) | |
download | hashie-f76d4c9613206f376b1e869cf45aa56a04471e40.tar.gz |
Merge branch 'master' of github.com:intridea/hashie
-rw-r--r-- | lib/hashie/mash.rb | 4 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index 31deae2..97af028 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -81,7 +81,7 @@ module Hashie # if there isn't a value already assigned to the key requested. def initializing_reader(key) ck = convert_key(key) - regular_writer(ck, Hashie::Mash.new) unless key?(ck) + regular_writer(ck, self.class.new) unless key?(ck) regular_reader(ck) end @@ -163,7 +163,7 @@ module Hashie def convert_value(val, duping=false) #:nodoc: case val - when ::Hashie::Mash + when self.class val.dup when ::Hash val = val.dup if duping diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index 4ad5ff4..5aa8818 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -155,6 +155,30 @@ describe Hashie::Mash do record['submash'].should be_kind_of(SubMash) end + it "should respect the class when passed a bang method for a non-existent key" do + record = Hashie::Mash.new + record.non_existent!.should be_kind_of(Hashie::Mash) + + class SubMash < Hashie::Mash + end + + son = SubMash.new + son.non_existent!.should be_kind_of(SubMash) + end + + it "should respect the class when converting the value" do + record = Hashie::Mash.new + record.details = Hashie::Mash.new({:email => "randy@asf.com"}) + record.details.should be_kind_of(Hashie::Mash) + + class SubMash < Hashie::Mash + end + + son = SubMash.new + son.details = Hashie::Mash.new({:email => "randyjr@asf.com"}) + son.details.should be_kind_of(SubMash) + end + describe '#respond_to?' do it 'should respond to a normal method' do Hashie::Mash.new.should be_respond_to(:key?) |