[#4595] New block syntax — Daniel Amelang <daniel.amelang@...>

I'm really sorry if this isn't the place to talk about this. I've

25 messages 2005/03/21
[#4606] Re: New block syntax — "David A. Black" <dblack@...> 2005/03/21

Hi --

[#4629] Re: New block syntax — "Sean E. Russell" <ser@...> 2005/03/30

On Monday 21 March 2005 16:17, David A. Black wrote:

[#4648] about REXML::Encoding — speakillof <speakillof@...>

Hi.

15 messages 2005/03/31
[#4659] Re: about REXML::Encoding — "Sean E. Russell" <ser@...> 2005/04/04

On Thursday 31 March 2005 09:44, speakillof wrote:

Re: want_object? - possible?

From: Daniel Berger <djberg96@...>
Date: 2005-03-25 01:05:32 UTC
List: ruby-core #4619
--- nobu.nokada@softhome.net wrote:
> Hi,
> 
> At Wed, 23 Mar 2005 02:38:54 +0900,
> Berger, Daniel wrote in [ruby-core:04611]:
> > Would it be possible to add a want_object? method
> that checks calling
> > context?  This would allow users to pass different
> values based on
> > calling contex, and would neatly solve the "what
> should bang methods
> > return" debate.
> 
> I don't think it is absolutely impossible, but,
> 
> > Here's some theoretical syntax:
> > 
> > class String
> >    def test!
> >       if want_object?
> >          return self
> >       end
> >       nil
> >    end
> > end
> > 
> > s = "hello"
> > s.test!      # returns nil
> > s.test!.chop # self ("hello") is returned from
> test!
> > 
> > result = s.test! # still returns nil
> 
> Why nil?  The return value seems to be used in the
> assignment?

But it's not being used as part of a method call, i.e.
it's not a receiver.

Please take a look at
http://search.cpan.org/~robin/Want-0.08/Want.pm for
more of an idea of what the Want module does.

Keep in mind that some of the contexts mentioned there
do not apply to Ruby, e.g. lvalue subs.  In fact, most
may not.  But, if there were some way for a method to
detect whether it's part of a chain in advance, that
might be useful.

Regards,

Dan


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

In This Thread

Prev Next