Class: RecursiveStruct
- Inherits:
-
Object
- Object
- RecursiveStruct
- Includes:
- Data
- Defined in:
- lib/recursive_struct.rb,
lib/recursive_struct/data.rb,
lib/recursive_struct/version.rb
Defined Under Namespace
Modules: Data
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ RecursiveStruct
constructor
A new instance of RecursiveStruct.
- #method_missing(name, *args, &block) ⇒ Object
Methods included from Data
#data, #get_data, #send_data, #set_data
Constructor Details
#initialize(hash = nil) ⇒ RecursiveStruct
Returns a new instance of RecursiveStruct.
6 7 8 |
# File 'lib/recursive_struct.rb', line 6 def initialize(hash = nil) hash.each { |key, value| set_data(key, value) } if hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/recursive_struct.rb', line 10 def method_missing(name, *args, &block) key = name.to_s if key.include?('=') add_setter(key.chomp('='), *args) elsif data.respond_to?(key) send_data(key, *args, &block) elsif args.length == 0 get_data(key) else super(name, *args, &block) end end |