Created
August 31, 2015 15:32
-
-
Save blake41/44894ca20fb0f10e1973 to your computer and use it in GitHub Desktop.
This file contains 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
require 'pry' | |
require 'pry-nav' | |
class Person | |
def initialize(att) | |
self.class.class_eval do | |
att.each do |method, value| | |
define_method(method) do | |
instance_variable_get("@#{method}") | |
end | |
define_method("#{method}=") do |arg| | |
instance_variable_set("@#{method}", arg) | |
end | |
end | |
end | |
att.each do |key, value| | |
public_send("#{key}=", value) | |
end | |
end | |
end | |
attributes_hash = {:name => "blake", :height => 7, :color => "green"} | |
person = Person.new(attributes_hash) | |
binding.pry | |
person |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment