Created
September 26, 2014 21:45
-
-
Save mzemel/1e0d0248ad2cf45fa9b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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