Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed attr_reader for recursive; Also using respond_to?(:to_hash) i…
…nstead of is_a?(Hash)
  • Loading branch information
abhionlyone committed Oct 16, 2018
commit 852f0e3fa00d9fe148047df2f2d629d042509be0
6 changes: 2 additions & 4 deletions lib/ostruct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
# of these properties compared to using a Hash or a Struct.
#
class OpenStruct
attr_reader :recursive

#
# Creates a new OpenStruct object. By default, the resulting OpenStruct
# object will have no attributes.
Expand All @@ -95,7 +93,7 @@ def initialize(hash=nil, is_recursive=false)
if hash
hash.each_pair do |k, v|
k = k.to_sym
@table[k] = (recursive && v.is_a?(Hash)) ? OpenStruct.new(v,true) : v
@table[k] = (@recursive && v.respond_to?(:to_hash)) ? OpenStruct.new(v,true) : v

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenStruct.new(v, options) or OpenStruct.new(v, recursive: true)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be OpenStruct.new(v, options). Will update the PR in a bit.

end
end
end
Expand Down Expand Up @@ -204,7 +202,7 @@ def method_missing(mid, *args) # :nodoc:
if len != 1
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
end
modifiable?[new_ostruct_member!(mname)] = (recursive && args[0].is_a?(Hash)) ? OpenStruct.new(args[0],true) : args[0]
modifiable?[new_ostruct_member!(mname)] = (@recursive && args[0].respond_to?(:to_hash)) ? OpenStruct.new(args[0],true) : args[0]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here
OpenStruct.new(v, recursive: true)

elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid #
if @table.key?(mid)
new_ostruct_member!(mid) unless frozen?
Expand Down