Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:intridea/hashie
  • Loading branch information
Michael Bleigh committed Aug 31, 2010
2 parents 18479a2 + 54f9bdd commit f76d4c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/hashie/mash.rb
Expand Up @@ -81,7 +81,7 @@ def []=(key,value) #:nodoc:
# 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

Expand Down Expand Up @@ -163,7 +163,7 @@ def convert_key(key) #:nodoc:

def convert_value(val, duping=false) #:nodoc:
case val
when ::Hashie::Mash
when self.class
val.dup
when ::Hash
val = val.dup if duping
Expand Down
24 changes: 24 additions & 0 deletions spec/hashie/mash_spec.rb
Expand Up @@ -155,6 +155,30 @@ class SubMash < Hashie::Mash
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?)
Expand Down

0 comments on commit f76d4c9

Please sign in to comment.