Skip to content

Instantly share code, notes, and snippets.

@memetical
Forked from anonymous/Person2
Created October 31, 2012 23:30
Show Gist options
  • Save memetical/3990632 to your computer and use it in GitHub Desktop.
Save memetical/3990632 to your computer and use it in GitHub Desktop.
rubyEx2
class Person
attr_accessor :name, :hobbies
def initialize(params)
params.each_key {|key|
begin
self.send("#{key}=".to_sym, params[key])
rescue
raise UnknownAttributeError
end
}
end
end
#argument_hash = {:name => "Dagobert", :hobbies => "Money"}
argument_hash = {:name => "Dagobert", :hobbies => "Money",:nonexistentfield => "some Value"}
p1 = Person.new(argument_hash)
puts p1.name
puts p1.hobbies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment