Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: intridea/hashie
base: 6d21c68685
...
head fork: intridea/hashie
compare: a4778140a4
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jun 04, 2012
@jch jch respect other Hashie::Hash subclasses when assigning a value
When assigning a raw ruby Hash, the hash should be converted
to the current subclass. But when assigning an existing
subclass, we should keep the existing subclass's type.

Example:

h = {:foo => 'bar'}
m = Hashie::Mash.new
m.value = h
m.value.class  # Hashie::Mash

class SubMash < Hashie::Mash
end

h = SubMash.new(:foo => 'bar')
m = Hashie::Mash.new
m.value = h
m.value.class  # Hashie::SubMash  <- should not be converted to a Mash
3fa6126
@mbleigh mbleigh Merge pull request #47 from jch/master
respect other Hashie::Hash subclasses when assigning a value
a477814
Showing with 9 additions and 3 deletions.
  1. +2 −0  lib/hashie/mash.rb
  2. +7 −3 spec/hashie/mash_spec.rb
View
2  lib/hashie/mash.rb
@@ -203,6 +203,8 @@ def convert_value(val, duping=false) #:nodoc:
case val
when self.class
val.dup
+ when Hash
+ duping ? val.dup : val
when ::Hash
val = val.dup if duping
self.class.new(val)
View
10 spec/hashie/mash_spec.rb
@@ -236,13 +236,17 @@ class SubMash < Hashie::Mash
record = Hashie::Mash.new
record.details = Hashie::Mash.new({:email => "randy@asf.com"})
record.details.should be_kind_of(Hashie::Mash)
+ end
+
+ it "should respect another subclass when converting the value" do
+ record = Hashie::Mash.new
class SubMash < Hashie::Mash
end
- son = SubMash.new
- son.details = Hashie::Mash.new({:email => "randyjr@asf.com"})
- son.details.should be_kind_of(SubMash)
+ son = SubMash.new({:email => "foo@bar.com"})
+ record.details = son
+ record.details.should be_kind_of(SubMash)
end
describe '#respond_to?' do

No commit comments for this range

Something went wrong with that request. Please try again.