class Motion::OpenStruct
Constants
- VERSION
Public Class Methods
new(hash)
click to toggle source
# File lib/motion-ostruct/open_struct.rb, line 4 def initialize(hash) @struct = ::Struct.new(*hash.keys.map { |k| k.to_sym }) @struct = @struct.new(*hash.values) end
Public Instance Methods
==(other)
click to toggle source
# File lib/motion-ostruct/open_struct.rb, line 9 def ==(other) to_h == other.to_h end
method_missing(method_name, *args, &block)
click to toggle source
# File lib/motion-ostruct/open_struct.rb, line 13 def method_missing(method_name, *args, &block) if method_name.to_s.index('=') && !@struct.respond_to?(method_name) vals = @struct.to_h.values getter_name = method_name.to_s.gsub('=', '') getters = ((@struct.to_h.keys.map { |k| k.to_sym }) + [getter_name.to_sym]) @struct = ::Struct.new(*getters) @struct = @struct.new(*vals) end @struct.send(method_name, *args, &block) end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/motion-ostruct/open_struct.rb, line 24 def respond_to_missing?(method_name, include_private = false) return true if @struct.respond_to?(method_name) return true if super end