Tags

class Dog
  attr_accessor :name, :breed

  def initialize(*h)
    if h.length == 1 && h.first.kind_of?(Hash)
      h.first.each { |k,v| send("#{k}=",v) }
    end
  end
end

my_puppy = Dog.new(:name => "Bantay", :breed => "dooberman")
my_puppy.instance_variable_get("@name") # returns Bantay
Advertisements