8000 adding a #to_hash alias for #to_h · paramadeep/recursive-open-struct@adcf6bf · GitHub
[go: up one dir, main page]

Skip to content

Commit adcf6bf

Browse files
committed
adding a #to_hash alias for #to_h
1 parent 2b1499b commit adcf6bf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/recursive_open_struct.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def to_h
2121
end
2222
end
2323

24+
alias_method :to_hash, :to_h
25+
2426
def new_ostruct_member(name)
2527
name = name.to_sym
2628
unless self.respond_to?(name)

spec/recursive_open_struct_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848

4949
describe "improvements on OpenStruct" do
5050
it "can be converted back to a hash" do
51-
h = { :asdf => 'John Smith' }
51+
blank_obj = Object.new
52+
h = {:asdf => 'John Smith', :foo => [{:bar => blank_obj}, {:baz => nil}]}
5253
ros = RecursiveOpenStruct.new(h)
5354
ros.to_h.should == h
55+
ros.to_hash.should == h
5456
end
5557
end
5658

@@ -237,7 +239,7 @@
237239

238240
it "creates nested objects via subclass" do
239241
RecursiveOpenStructSubClass = Class.new(RecursiveOpenStruct)
240-
242+
241243
rossc = RecursiveOpenStructSubClass.new({ :one => [{:two => :three}] }, recurse_over_arrays: true)
242244

243245
rossc.one.first.class.should == RecursiveOpenStructSubClass

0 commit comments

Comments
 (0)
0