Skip to content

Commit 852f0e3

Browse files
committed
Removed attr_reader for recursive; Also using respond_to?(:to_hash) instead of is_a?(Hash)
1 parent 50ed63e commit 852f0e3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/ostruct.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@
7373
# of these properties compared to using a Hash or a Struct.
7474
#
7575
class OpenStruct
76-
attr_reader :recursive
77-
7876
#
7977
# Creates a new OpenStruct object. By default, the resulting OpenStruct
8078
# object will have no attributes.
@@ -95,7 +93,7 @@ def initialize(hash=nil, is_recursive=false)
9593
if hash
9694
hash.each_pair do |k, v|
9795
k = k.to_sym
98-
@table[k] = (recursive && v.is_a?(Hash)) ? OpenStruct.new(v,true) : v
96+
@table[k] = (@recursive && v.respond_to?(:to_hash)) ? OpenStruct.new(v,true) : v
9997
end
10098
end
10199
end
@@ -204,7 +202,7 @@ def method_missing(mid, *args) # :nodoc:
204202
if len != 1
205203
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
206204
end
207-
modifiable?[new_ostruct_member!(mname)] = (recursive && args[0].is_a?(Hash)) ? OpenStruct.new(args[0],true) : args[0]
205+
modifiable?[new_ostruct_member!(mname)] = (@recursive && args[0].respond_to?(:to_hash)) ? OpenStruct.new(args[0],true) : args[0]
208206
elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
209207
if @table.key?(mid)
210208
new_ostruct_member!(mid) unless frozen?

0 commit comments

Comments
 (0)