Class: Hiiro::AnyStruct
- Inherits:
-
Object
- Object
- Hiiro::AnyStruct
- Defined in:
- lib/hiiro/any_struct.rb
Instance Attribute Summary collapse
-
#_raw_data ⇒ Object
readonly
Returns the value of attribute _raw_data.
Class Method Summary collapse
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(*args, **raw_data) ⇒ AnyStruct
constructor
A new instance of AnyStruct.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(*args, **raw_data) ⇒ AnyStruct
Returns a new instance of AnyStruct.
11 12 13 14 15 |
# File 'lib/hiiro/any_struct.rb', line 11 def initialize(*args, **raw_data) hashes = args.select{|arg| arg.is_a?(Hash) }.inject(:merge) @_raw_data = hashes.merge(raw_data) @_raw_data.each { |k,v| set(k, v) } end |
Instance Attribute Details
#_raw_data ⇒ Object (readonly)
Returns the value of attribute _raw_data.
9 10 11 |
# File 'lib/hiiro/any_struct.rb', line 9 def _raw_data @_raw_data end |
Class Method Details
.recursive_new(*args, **raw_data) ⇒ Object
3 4 5 6 7 |
# File 'lib/hiiro/any_struct.rb', line 3 def self.recursive_new(*args, **raw_data) args.push(raw_data).select { |arg| arg.is_a?(Hash) }.inject(:merge) end |
Instance Method Details
#get(key) ⇒ Object
25 26 27 |
# File 'lib/hiiro/any_struct.rb', line 25 def get(key) _raw_data[key.to_sym] end |
#set(key, value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/hiiro/any_struct.rb', line 17 def set(key, value) _raw_data[key.to_sym] = value define_singleton_method(key.to_sym) do _raw_data[key.to_sym] end end |