Skip to content

Instantly share code, notes, and snippets.

@lain0
Last active September 19, 2018 13:50
Show Gist options
  • Save lain0/48b04f96b6fc3b6cfcce7456c5910936 to your computer and use it in GitHub Desktop.
Save lain0/48b04f96b6fc3b6cfcce7456c5910936 to your computer and use it in GitHub Desktop.
ruby attr_accessor
```
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 =>"132@mail.ru",
: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