module SuperStruct::InstanceMethods

Public Class Methods

new(*input) click to toggle source
Calls superclass method
# 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

Public Instance Methods

==(other) click to toggle source
# File lib/super_struct.rb, line 34
def ==(other)
  other.respond_to?(:attributes) && attributes == other.attributes
end
attributes() click to toggle source
# File lib/super_struct.rb, line 17
def attributes
  members.inject({}) do |attributes, member|
    attributes[member] = send(member)
    attributes
  end
end
deep_convert!() click to toggle source
# File lib/super_struct.rb, line 24
def deep_convert!
  members.each do |member|
    if self[member].respond_to?(:has_key?) && self[member].size > 0
      self[member] = ::SuperStruct.from_hash(self[member])
      self[member].deep_convert!
    end
  end
  self
end