Skip to content

Instantly share code, notes, and snippets.

@blake41
Created August 31, 2015 15:32
Show Gist options
  • Save blake41/44894ca20fb0f10e1973 to your computer and use it in GitHub Desktop.
Save blake41/44894ca20fb0f10e1973 to your computer and use it in GitHub Desktop.
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