Sorry, you're right. I phrased my question wrong. Let's try this:
class Foo < ActiveRecord::Base
private
# really protect attribute bar
def bar
read_attribute :bar
end
def bar=(val)
write_attribute :bar, val
end
end
Now Foo.new.respond_to?(:bar) really _should_ return false, but it
doesn't. This method isn't checked before @attributes is.
-Gaius
On Tue, Sep 2, 2008 at 2:00 PM, Jonathan Weiss <[EMAIL PROTECTED]> wrote:
>
>> I would think that Foo.new.respond_to?(:bar) would be false, but it
>> returns true.
>
> It should be true as the Foo instance responds to a method called bar.
>
>> This is because the definition of :respond_to? checks
>> whether @attributes.include?(method_name), but doesn't take attribute
>> protection into account.
>>
>
> It doesn't check attributes, it checks the actual methods on the
> object. It is independent of Rails.
>
>> Foo thus does not abide by the general contract of respond_to?:
>> "respond_to?(:baz) returns true if and only if call(:baz) does not
>> raise a NoMethodError."
>
>
> Hu? Foo.new *has* a bar method. It just doesn't allow you to set it in
> mass-assignment.
>
> Jonathan
>
> --
> Jonathan Weiss
> http://blog.innerewut.de
> http://twitter.com/jweiss
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---