Last active
September 19, 2018 13:50
-
-
Save lain0/48b04f96b6fc3b6cfcce7456c5910936 to your computer and use it in GitHub Desktop.
ruby attr_accessor
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 Account | |
attr_accessor :name, :date, :email, :notes | |
def assign_values(values) | |
values.each_key do |k| | |
self.send("#{k}=",values[k]) | |
end | |
end | |
end | |
user_info = { | |
:name => "Serj", | |
:date =>"2015-10-13", | |
:email =>"[email protected]", | |
:notes => "ok" | |
} | |
account = Account.new | |
account.assign_values(user_info) | |
puts account.inspect | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment