Created
April 2, 2010 20:34
-
-
Save mlomnicki/353673 to your computer and use it in GitHub Desktop.
active_record_protected
This file contains 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
# script/generate model Post content:text | |
class Post < ActiveRecord::Base | |
alias :full_content :content | |
end | |
This file contains 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
# 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) | |
This file contains 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
# 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