Skip to content

MR10a Metaprogramming Lab

Dave Strus edited this page Jan 31, 2016 · 1 revision

LAB: Metaprogramming

Mutant#attributes

Add an instance method to Mutant called attributes

class Mutant
  # ...

  def attributes
  end
end

Mutant#attributes should return a hash with the attribute names as keys, and the attribute values as the hash values.

Given the following:

m = Mutant.new
m.real_name = 'Vito'
m.mutant_name = 'Zyphoerex'
m.power = 'Using rare consonants'

Calling m.attributes should return this hash:

{
  real_name: 'Vito',
  mutant_name: 'Zyphoerex',
  power: 'Using rare consonants'
}

Make it work without writing real_name, mutant_name, or power in the attributes method.