Module: StrongStruct::InstanceMethods

Defined in:
lib/strong_struct.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



49
50
51
52
53
54
55
# File 'lib/strong_struct.rb', line 49

def attributes
  hash = {}
  accessors.each do |attr|
    hash[attr] = send(attr)
  end
  hash
end

#initialize(params = {}) ⇒ Object



43
44
45
46
47
# File 'lib/strong_struct.rb', line 43

def initialize(params = {})
  params.each do |attr, value|
    send "#{attr}=", value
  end if params
end

#inspectObject



65
66
67
68
69
70
# File 'lib/strong_struct.rb', line 65

def inspect
  base = super
  klass_name = class_name
  return base unless klass_name != 'Object'
  base.gsub(/^#<#<Class:/, "#<#<#{klass_name}:")
end

#to_sObject



57
58
59
60
61
62
# File 'lib/strong_struct.rb', line 57

def to_s
  base = super
  klass_name = class_name
  return base unless klass_name != 'Object'
  base.gsub(/^#<#<Class:/, "#<#<#{klass_name}:")
end