Skip to content

Instantly share code, notes, and snippets.

@mlomnicki
Created April 2, 2010 20:34
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 mlomnicki/353673 to your computer and use it in GitHub Desktop.
Save mlomnicki/353673 to your computer and use it in GitHub Desktop.
active_record_protected
# script/generate model Post content:text
class Post < ActiveRecord::Base
alias :full_content :content
end
# script/generate model Post content:text
class Post < ActiveRecord::Base
protected
def content
"Is content protected?"
end
end
# should print 'Is content procted' huh?
puts Post.new.send(:content)
# script/generate model Post content:text
class Post < ActiveRecord::Base
end
puts Post.method_defined?(:content)
# false
puts Post.instance_methods.include?('content')
# false
Post.new.content
puts Post.method_defined?(:content)
# true
puts Post.instance_methods.include?('content')
# true
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4317-inconsistent-method_defined-bevahiour
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment