Skip to content

Instantly share code, notes, and snippets.

@mnaser
Forked from denysonique/my_model.rb
Created July 1, 2011 17:12
Show Gist options
  • Save mnaser/1058981 to your computer and use it in GitHub Desktop.
Save mnaser/1058981 to your computer and use it in GitHub Desktop.
Is there a cleaner/simpler way of doing this?
class MyModel < ActiveRecord::Base
after_initialize :setup_defaults
attr_accessor :foo_bar
def setup_defaults
foo_bar ||= "my default value"
end
end
@mnaser
Copy link
Author

mnaser commented Jul 1, 2011

The ||= means set value if it's empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment