Module: SuperStruct::InstanceMethods
- Defined in:
- lib/super_struct.rb
Instance Method Summary collapse
Instance Method Details
#attributes ⇒ Object
17 18 19 20 21 22 |
# File 'lib/super_struct.rb', line 17 def attributes members.inject({}) do |attributes, member| attributes[member] = send(member) attributes end end |
#initialize(*input) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/super_struct.rb', line 5 def initialize(*input) if input.first.respond_to?(:has_key?) keys, values = input.first.sort.transpose unless keys.map(&:to_sym) == members raise ArgumentError.new("#{self.class.name} expects a hash with keys #{members.join(', ')}") end super(*values) else super(*input) end end |