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.0.6'
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ RecursiveStruct
constructor
A new instance of RecursiveStruct.
- #method_missing(name, *args) ⇒ 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 9 10 11 12 |
# File 'lib/recursive_struct.rb', line 6 def initialize(hash = nil) if hash hash.each do |key, value| set_data(key, value) end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/recursive_struct.rb', line 14 def method_missing(name, *args) key = name.to_s if key.include?('=') add_setter(key.chomp('='), *args) elsif data.respond_to?(key) send_data(key, *args) elsif args.length == 0 get_data(key) else super(name, *args) end end |