module StrongStruct::InstanceMethods

Public Class Methods

new(params = {}) click to toggle source
# File lib/strong_struct.rb, line 24
def initialize(params = {})
  params.each do |attr, value|
    send "#{attr}=", value
  end if params
end

Public Instance Methods

attributes() click to toggle source
# File lib/strong_struct.rb, line 30
def attributes
  hash = {}
  accessors.each do |attr|
    hash[attr] = send(attr)
  end
  hash
end

Private Instance Methods

accessors() click to toggle source
# File lib/strong_struct.rb, line 40
def accessors
  @accessors ||= get_accessors
end
get_accessors() click to toggle source
# File lib/strong_struct.rb, line 44
def get_accessors
  klass = self.class

  attrs = []

  while klass.respond_to?(:accessors)
    if klass.accessors.empty?
      klass = klass.superclass
    else
      attrs = klass.accessors
      break
    end
  end

  attrs
end