Sha256: e105afb609de194989984e8be73ea284c5bb0d1a9dfe26eddca7305042f84199
Contents?: true
Size: 1.24 KB
Versions: 92
Compression:
Stored size: 1.24 KB
Contents
# 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) @table = {} 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 StandardError raise RuntimeError, "can't modify frozen #{self.class}", caller(3) end @table end protected :modifiable def new_ostruct_member(name) name = name.to_sym unless respond_to?(name) define_singleton_method(name) { @table[name] } define_singleton_method("#{name}=") { |x| modifiable[name] = x } end name end protected :new_ostruct_member def method_missing(mid, *args) # :nodoc: mname = mid.id2name 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
Version data entries
92 entries across 92 versions & 1 rubygems