Class: StrictOpenStruct
- Inherits:
-
Object
- Object
- StrictOpenStruct
- Defined in:
- lib/strict_open_struct.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ StrictOpenStruct
constructor
A new instance of StrictOpenStruct.
-
#method_missing(method_name, *args, &block) ⇒ Object
Raises NoMethodError unless the underlying OpenStruct responds to the method or the method is a setter.
Constructor Details
#initialize(*args) ⇒ StrictOpenStruct
Returns a new instance of StrictOpenStruct.
5 6 7 |
# File 'lib/strict_open_struct.rb', line 5 def initialize(*args) @open_struct = OpenStruct.new(*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Raises NoMethodError unless the underlying OpenStruct responds to the method or the method is a setter
11 12 13 14 15 16 17 |
# File 'lib/strict_open_struct.rb', line 11 def method_missing(method_name, *args, &block) if @open_struct.respond_to?(method_name) || method_name =~ /=$/ @open_struct.send(method_name, *args, &block) else fail NoMethodError, "undefined method `#{method_name}' for #{self}" end end |