Skip to content

Instantly share code, notes, and snippets.

@mzemel
Created September 26, 2014 21:45
Show Gist options
  • Save mzemel/1e0d0248ad2cf45fa9b5 to your computer and use it in GitHub Desktop.
Save mzemel/1e0d0248ad2cf45fa9b5 to your computer and use it in GitHub Desktop.
class Person
attr_accessor :name, :age, :weight
def initialize(hash)
hash.each do |key, value|
setter_method = key.to_s + "="
send(setter_method, value)
end
end
end
p = Person.new(name: 'Bob', age: 10, weight: 100)
p.name
# => Bob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment