Skip to content

Instantly share code, notes, and snippets.

@awilkening
Created September 5, 2012 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awilkening/3629539 to your computer and use it in GitHub Desktop.
Save awilkening/3629539 to your computer and use it in GitHub Desktop.
class Person < ActiveRecord::Base
attr_accessor :dont_set_name
def name
@name
end
def name=(attr)
@name = attr unless dont_set_name
end
end
a = Person.new
a.attributes = {name: 'George', dont_set_name: true}
a.name
#=> 'George'
a = Person.new
a.attributes = {dont_set_name: true, name: 'George'}
a.name
#=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment