Forum: Ruby attr_accessor question

Posted by Edoardo Rossi (Guest)
on 2013-01-13 17:04
(Received via mailing list)
Hello ruby-talk.

I hope this isn't a too silly question, but: who respond_to? true at
attr_accessor?

irb(main):028:0> Module.respond_to?(:to_s)
=> true
irb(main):029:0> Module.respond_to?(:attr_accessor)
=> false
irb(main):030:0> Module.respond_to?(:attr)
=> false

I understand it's a class_macro in Module#attr_accessor...
#attr_accessor, #attr_reader, #attr_writer


Thanks to all.

e.
Posted by Stefano Crocco (crocco)
on 2013-01-13 17:15
(Received via mailing list)
On Monday 14 January 2013 Edoardo Rossi wrote
> => false
>
> I understand it's a class_macro in Module#attr_accessor...
> #attr_accessor, #attr_reader, #attr_writer
>
>
> Thanks to all.
>
> e.

attr_accessor and similar are private methods of class Module. Because 
of
this, respond_to? only returns true if you pass true as second argument:

Module.respond_to? :attr_reader, true
=> true

Module.respond_to? :attr_reader
=> false

I hope this helps

Stefano
Posted by Edoardo Rossi (Guest)
on 2013-01-13 17:25
(Received via mailing list)
On Sun, Jan 13, 2013 at 5:14 PM, Stefano Crocco 
<stefano.crocco@alice.it> wrote:
>> irb(main):030:0> Module.respond_to?(:attr)
> attr_accessor and similar are private methods of class Module. Because of
> Stefano
>

Thanks Stefano.
It was silly just as I suspected.

Thanks again (e buona serata...).

e.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.