class EndangeredSpecies::Animal

dynamically assigned Animal object based on a hash of key value pairs

Attributes

attribute_names[R]

Public Class Methods

assign_attribute_keys(attributes) click to toggle source
# File lib/endangered_species/animal.rb, line 23
def self.assign_attribute_keys(attributes)
  attributes.keys.each do |attribute|
    attr_accessor attribute
  end
end
new(attributes = {}) click to toggle source
# File lib/endangered_species/animal.rb, line 6
def initialize(attributes = {})
  @attribute_names = []
  assign_attributes(attributes)
end

Public Instance Methods

assign_attribute_values(attributes) click to toggle source
# File lib/endangered_species/animal.rb, line 16
def assign_attribute_values(attributes)
  attributes.each do |k, v|
    send("#{k}=", v)
    @attribute_names << k.to_s
  end
end
assign_attributes(attributes) click to toggle source
# File lib/endangered_species/animal.rb, line 11
def assign_attributes(attributes)
  self.class.assign_attribute_keys(attributes)
  assign_attribute_values(attributes)
end