Ross Bamford
12/29/2006 12:14:00 PM
On Fri, 29 Dec 2006 11:12:54 -0000, yrashk@gmail.com <yrashk@gmail.com> =
=
wrote:
> I have the following code:
>
> class ReturnSelfAfter
>
> def initialize(context)
> @context =3D 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 =3D 1
> =3D> 1
>
> While #abc returns C class instance, of course:
>
>>> C.new.return_self_after.abc
> =3D> #<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, n=
o =
matter what you try to return from the method. I guess it's a question o=
f =
consistency.
-- =
Ross Bamford - rosco@roscopeco.remove.co.uk