File tree 1 file changed +5
-4
lines changed
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -87,13 +87,14 @@ class OpenStruct
87
87
#
88
88
# data # => #<OpenStruct country="Australia", capital="Canberra">
89
89
#
90
- def initialize ( hash = nil , is_recursive = false )
90
+ def initialize ( hash = nil , options = { recursive : true } )
91
91
@table = { }
92
- @recursive = is_recursive
92
+ @recursive = options . fetch ( :recursive , false )
93
+ puts @recursive
93
94
if hash
94
95
hash . each_pair do |k , v |
95
96
k = k . to_sym
96
- @table [ k ] = ( @recursive && v . respond_to? ( :to_hash ) ) ? OpenStruct . new ( v , true ) : v
97
+ @table [ k ] = ( @recursive && v . respond_to? ( :to_hash ) ) ? OpenStruct . new ( v , { recursive : true } ) : v
97
98
end
98
99
end
99
100
end
@@ -202,7 +203,7 @@ def method_missing(mid, *args) # :nodoc:
202
203
if len != 1
203
204
raise ArgumentError , "wrong number of arguments (#{ len } for 1)" , caller ( 1 )
204
205
end
205
- modifiable? [ new_ostruct_member! ( mname ) ] = ( @recursive && args [ 0 ] . respond_to? ( :to_hash ) ) ? OpenStruct . new ( args [ 0 ] , true ) : args [ 0 ]
206
+ modifiable? [ new_ostruct_member! ( mname ) ] = ( @recursive && args [ 0 ] . respond_to? ( :to_hash ) ) ? OpenStruct . new ( args [ 0 ] , { recursive : true } ) : args [ 0 ]
206
207
elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
207
208
if @table . key? ( mid )
208
209
new_ostruct_member! ( mid ) unless frozen?
You can’t perform that action at this time.
0 commit comments