This project is archived and is in readonly mode.
models' respond_to? does not honor private
Reported by Gaius Centus Novus | September 2nd, 2008 @ 11:14 PM | in 2.x
I want to make an attribute truly private, so I tried this:
class Foo < ActiveRecord::Base
# attribute bar
private
def bar
read_attribute :bar
end
def bar=(value)
write_attribute :bar, value
end
end
but Foo.new.respond_to?(:bar) returns true, where a normal (non-active-record) instance would return false for private methods.
This patch adds a check in respond_to? to honor private methods that shadow attributes.
Comments and changes to this ticket
-
Gaius Centus Novus September 3rd, 2008 @ 01:54 PM
that patch doesn't honor the parameter include_priv. Perhaps the following would be even better?
def respond_to?(method, include_priv = false) return true if super return include_priv if private_methods.include?(method_name) ... end
-
Pratik December 20th, 2008 @ 03:45 PM
- Assigned user set to Pratik
- State changed from new to wontfix
Is this still a problem ? Also, this is a bit tricky. I think it's worth discussing in the core list.
Could you please upload a patch against latest edge ? This one doesn't apply any longer.
I'll reopen once we have these issues handled.
Thanks.
-
Pratik December 20th, 2008 @ 03:45 PM
- State changed from wontfix to incomplete
-
Prem Sichanugrist (sikachu) January 22nd, 2010 @ 08:52 AM
- State changed from incomplete to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>