class StrictOpenStruct
Public Class Methods
new(*args)
click to toggle source
# File lib/strict_open_struct.rb, line 5 def initialize(*args) @open_struct = OpenStruct.new(*args) end
Public Instance Methods
==(other)
click to toggle source
# File lib/strict_open_struct.rb, line 23 def ==(other) @open_struct == other.instance_variable_get("@open_struct") end
[](key)
click to toggle source
# File lib/strict_open_struct.rb, line 27 def [](key) @open_struct.to_h.fetch(key.to_sym) end
method_missing(method_name, *args, &block)
click to toggle source
Raises NoMethodError unless the underlying OpenStruct responds to the method or the method is a setter
# File lib/strict_open_struct.rb, line 11 def method_missing(method_name, *args, &block) if open_struct_responds_to?(method_name) @open_struct.send(method_name, *args, &block) else failure(method_name) end end
respond_to_missing?(method_name, include_private = false)
click to toggle source
# File lib/strict_open_struct.rb, line 19 def respond_to_missing?(method_name, include_private = false) open_struct_responds_to?(method_name) end
Private Instance Methods
failure(method_name)
click to toggle source
# File lib/strict_open_struct.rb, line 33 def failure(method_name) fail NoMethodError, "undefined method `#{method_name}' for #{self}" end
open_struct_responds_to?(method_name)
click to toggle source
# File lib/strict_open_struct.rb, line 37 def open_struct_responds_to?(method_name) @open_struct.respond_to?(method_name) || method_name =~ /=$/ end