Permalink
Browse files

Do not convert child mashes, retain their class.

  • Loading branch information...
1 parent f299f63 commit f670fb3a7bbfb971b06cdc415e76b091667f933d Michael Bleigh committed Aug 19, 2010
Showing with 22 additions and 9 deletions.
  1. +6 −6 lib/hashie.rb
  2. +1 −1 lib/hashie/hash_extensions.rb
  3. +3 −1 lib/hashie/mash.rb
  4. +10 −0 spec/hashie/mash_spec.rb
  5. +2 −1 spec/spec.opts
View
@@ -1,9 +1,9 @@
-require 'hashie/hash_extensions'
-require 'hashie/hash'
-require 'hashie/mash'
-require 'hashie/dash'
-require 'hashie/clash'
-
module Hashie
+ autoload :HashExtensions, 'hashie/hash_extensions'
+ autoload :PrettyInspect, 'hashie/hash_extensions'
+ autoload :Hash, 'hashie/hash'
autoload :Trash, 'hashie/trash'
+ autoload :Mash, 'hashie/mash'
+ autoload :Dash, 'hashie/dash'
+ autoload :Clash, 'hashie/clash'
end
@@ -27,7 +27,7 @@ def hashie_stringify_keys
# Convert this hash into a Mash
def to_mash
- Hashie::Mash.new(self)
+ ::Hashie::Mash.new(self)
end
end
View
@@ -86,7 +86,7 @@ def initializing_reader(key)
alias_method :regular_dup, :dup
# Duplicates the current mash as a new mash.
def dup
- Mash.new(self, self.default)
+ self.class.new(self, self.default)
end
def key?(key)
@@ -141,6 +141,8 @@ def convert_key(key) #:nodoc:
def convert_value(val, duping=false) #:nodoc:
case val
+ when ::Hashie::Mash
+ val.dup
when ::Hash
val = val.dup if duping
self.class.new(val)
View
@@ -90,6 +90,16 @@ class MyMash < Hashie::Mash
record.son.class.should == MyMash
end
+ it "should not change the class of Mashes when converted" do
+ class SubMash < Hashie::Mash
+ end
+
+ record = Hashie::Mash.new
+ son = SubMash.new
+ record['submash'] = son
+ record['submash'].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?)
View
@@ -1,2 +1,3 @@
--colour
---format progress
+--format progress
+--backtrace

0 comments on commit f670fb3

Please sign in to comment.