File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -88,12 +88,13 @@ class OpenStruct
8888 #
8989 # data # => #<OpenStruct country="Australia", capital="Canberra">
9090 #
91- def initialize ( hash = nil )
91+ def initialize ( hash = nil , recursive = false )
9292 @table = { }
93+ @recursive = recursive
9394 if hash
9495 hash . each_pair do |k , v |
9596 k = k . to_sym
96- @table [ k ] = v . is_a? ( Hash ) ? OpenStruct . new ( v ) : v
97+ @table [ k ] = ( recursive && v . is_a? ( Hash ) ) ? OpenStruct . new ( v , recursive : true ) : v
9798 end
9899 end
99100 end
@@ -202,7 +203,7 @@ def method_missing(mid, *args) # :nodoc:
202203 if len != 1
203204 raise ArgumentError , "wrong number of arguments (#{ len } for 1)" , caller ( 1 )
204205 end
205- modifiable? [ new_ostruct_member! ( mname ) ] = args [ 0 ] . is_a? ( Hash ) ? OpenStruct . new ( args [ 0 ] ) : args [ 0 ]
206+ modifiable? [ new_ostruct_member! ( mname ) ] = ( recursive && args [ 0 ] . is_a? ( Hash ) ) ? OpenStruct . new ( args [ 0 ] , recursive : true ) : args [ 0 ]
206207 elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
207208 if @table . key? ( mid )
208209 new_ostruct_member! ( mid ) unless frozen?
You can’t perform that action at this time.
0 commit comments