[#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:

want_object? - possible?

From: "Berger, Daniel" <Daniel.Berger@...>
Date: 2005-03-22 17:38:54 UTC
List: ruby-core #4611
Hi all,

I mentioned this on ruby-talk, but thought I should mention it here in
case it got buried.

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.

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

I suppose there's the danger of the slippery slope, where we start
adding more and more context checking methods, like want_lvalue?,
want_rvalue?, etc, and things get out of control.

But, I don't even know if this syntax is possible, so perhaps it's a
moot point.

Just an idea.

Regards,

Dan

PS - I actually brought this up about 3 years ago, but it didn't get too
much discussion.



In This Thread

Prev Next