Class: HStruct
- Inherits:
-
Struct
- Object
- Struct
- HStruct
- Defined in:
- lib/hstruct.rb
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ HStruct
constructor
A new instance of HStruct.
- #to_h ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ HStruct
Returns a new instance of HStruct.
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/hstruct.rb', line 2 def initialize(args = {}) raise ArgumentError unless args.is_a?(Enumerable) unless args.keys.first.is_a?(Symbol) args = args.each_with_object({}) do |(k,v), result| result[k.to_sym] = v end end super(*members.map { |m| args[m] }) end |
Instance Method Details
#to_h ⇒ Object
14 15 16 |
# File 'lib/hstruct.rb', line 14 def to_h Hash[each_pair.to_a] end |