Skip to content

Instantly share code, notes, and snippets.

@ivanbrennan
Created October 10, 2013 14:04
Show Gist options
  • Select an option

  • Save ivanbrennan/6918927 to your computer and use it in GitHub Desktop.

Select an option

Save ivanbrennan/6918927 to your computer and use it in GitHub Desktop.
person.rb
class Person
def initialize(attr_hash)
attr_hash.each do |property, value|
Person.send(:define_method, property) do
@property = value
end
end
end
end
@ivanbrennan

Copy link
Copy Markdown
Author

I'm not sure I understand why line 5 works here. Am I dynamically creating a symbol, like @name, @age, etc., or am I just reassigning the value of @property each time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment