Sha256: 9fcee1af69b58aedfe40509f9692fb5d6cb0e92dc5620d5f5b3941c74df7b83a
Contents?: true
Size: 1.26 KB
Versions: 68
Compression:
Stored size: 1.26 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 = {} if hash hash.each_pair do |k, v| k = k.to_sym @table[k] = v new_ostruct_member(k) end end end def modifiable begin @modifiable = true rescue 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
68 entries across 68 versions & 1 rubygems