Forum: Ruby Bug or Feature? (proxying methods)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae2b294e24fd2e472bfca45ab19050c5?d=identicon&s=25 yrashk@gmail.com (Guest)
on 2006-12-29 12:15
(Received via mailing list)
I have the following code:

class ReturnSelfAfter

  def initialize(context)
    @context = context
  end

  def method_missing(sym,*args,&block)
    @context.send sym, *args, &block
    @context
  end

end

class Object
  def return_self_after
    ReturnSelfAfter.new(self)
  end
end

While it works fine proxying most of methods (not inclusive standard
ones, of course), it seems to fail on setters:

 class C ; attr_accessor :abc ; end

>> C.new.return_self_after.abc = 1
=> 1

While #abc returns C class instance, of course:

>> C.new.return_self_after.abc
=> #<C:0x705014>

So, is it a bug or a feature? Or am I just missing something?

(ruby 1.8.4 (2005-12-24) [i686-darwin8.7.1])

Thank you in advance
82e62c756d89bc6fa0a0a2d7f2b1e617?d=identicon&s=25 Ross Bamford (Guest)
on 2006-12-29 13:15
(Received via mailing list)
On Fri, 29 Dec 2006 11:12:54 -0000, yrashk@gmail.com <yrashk@gmail.com>
wrote:

>     @context
> While it works fine proxying most of methods (not inclusive standard
> => #<C:0x705014>
>
> So, is it a bug or a feature? Or am I just missing something?
>

It's a feature - assignment in ruby always returns the assigned value,
no
matter what you try to return from the method. I guess it's a question
of
consistency.
This topic is locked and can not be replied to.