lib/ostruct.rb in trusty-cms-4.1.2 vs lib/ostruct.rb in trusty-cms-4.1.3

- old
+ new

@@ -1,25 +1,22 @@ # patching OpenStruct due to Ruby 2.3.1 upgrade # See more here: http://stackoverflow.com/questions/39278864/openstruct-issue-with-ruby-2-3-1/39280374#39280374 class OpenStruct - - def initialize(hash=nil) + def initialize(hash = nil) @table = {} - if hash - hash.each_pair do |k, v| - k = k.to_sym - @table[k] = v - new_ostruct_member(k) - end + hash&.each_pair do |k, v| + k = k.to_sym + @table[k] = v + new_ostruct_member(k) end end def modifiable begin @modifiable = true - rescue + rescue StandardError raise RuntimeError, "can't modify frozen #{self.class}", caller(3) end @table end protected :modifiable @@ -39,16 +36,16 @@ len = args.length if mname.chomp!('=') if len != 1 raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1) end + modifiable[new_ostruct_member(mname)] = args[0] elsif len == 0 @table[mid] else err = NoMethodError.new "undefined method `#{mid}' for #{self}", mid, args err.set_backtrace caller(1) raise err end end - end \ No newline at end of file