Ask a Question related to Ruby, Design and Development.
-
dhtapp #1
Messages to nil
Hi,
One of the things I got accustomed to in Objective C was nil's behavior as a
universal message sink: You could send nil anything, and you'd get nil
back.
No big deal, really, except that it made message cascades (which in Ruby
would look like Java- or OGNL-style keypaths) a bit easier to code, without
having to stop off at every point in the path and use an if-statement to see
if there was a real object still listening. When I switched over to
predominately using Java a few years back, it took me a couple of painful
days to change that habit (not to mention remembering to use "null"
instead...literally the most besetting annoyance I inflicted on myself in
trying to learn Java).
Just curious: would it be worth petitioning the Power That Be for a global
switch that induced that kind of behavior in nil? Would there be any
catastrophic consequences? (Please be gentle; I still have only the
faintest clue what I'm doing with Ruby, except enjoying it a great deal...)
- dan
dhtapp Guest
-
SMS messages from Windows
Hi there, Did anyone send free SMS mobile messages from Perl under Windows environment ? If yes, can you please share your "how to ?" Thanks... -
Pop up messages
Is there a way to stop all of the pop up messages, ie. pop up killers, kill messengers, etc.? All of these websites say that Windows XP allows... -
messages
I got a message from "stopip.dynu.com" that appeared on my computer telling me if i wanted to stop these messages to go to their website. I did and... -
Pop-up messages
I disabled pop-up messages once before, but since I had to get a new hard drive, they are back! I cannot remember how I disabled them before. ... -
IP Messages
Recently, my computer has been bombarded by internet ads. One website claims that microsoft included this ability in their Microsoft XP software... -
ts #2
Re: Messages to nil
>>>>> "d" == dhtapp <dhtapp@cox.net> writes:
d> Just curious: would it be worth petitioning the Power That Be for a global
d> switch that induced that kind of behavior in nil? Would there be any
d> catastrophic consequences?
Well, there were some related discussion about a Null pattern, see for
example
[url]http://www.ruby-talk.org/cgi-bin/vframe.rb/ruby/ruby-talk/17537?17391-25625[/url]
[url]http://www.ruby-talk.org/cgi-bin/vframe.rb/ruby/ruby-talk/17721?17655-25795[/url]
(these previous URL use frame)
[url]http://www.ruby-talk.org/17785[/url]
--
Guy Decoux
ts Guest
-
Reimer Behrends #3
Re: Messages to nil
dhtapp (dhtapp@cox.net) wrote:
[...]Does> Just curious: would it be worth petitioning the Power That Be for a global
> switch that induced that kind of behavior in nil? Would there be any
> catastrophic consequences? (Please be gentle; I still have only the
> faintest clue what I'm doing with Ruby, except enjoying it a great deal...)
def nil.method_missing(*args) nil end
do what you want?
Reimer Behrends
Reimer Behrends Guest
-
Robert Klemme #4
Re: Messages to nil
"dhtapp" <dhtapp@cox.net> schrieb im Newsbeitrag
news:2c6sb.12896$7B2.12145@fed1read04...as a> Hi,
>
> One of the things I got accustomed to in Objective C was nil's behaviorwithout> universal message sink: You could send nil anything, and you'd get nil
> back.
>
> No big deal, really, except that it made message cascades (which in Ruby
> would look like Java- or OGNL-style keypaths) a bit easier to code,see> having to stop off at every point in the path and use an if-statement topainful> if there was a real object still listening. When I switched over to
> predominately using Java a few years back, it took me a couple ofin> days to change that habit (not to mention remembering to use "null"
> instead...literally the most besetting annoyance I inflicted on myselfglobal> trying to learn Java).
>
> Just curious: would it be worth petitioning the Power That Be for adeal...)> switch that induced that kind of behavior in nil? Would there be any
> catastrophic consequences? (Please be gentle; I still have only the
> faintest clue what I'm doing with Ruby, except enjoying it a great
Well, instead of checking at each point you can simply catch
NoMethodError:
begin
"foo".bar.baz.foo.doit( "yes" )
rescue NoMethodError => e
puts "ERROR in method #{e.name}( #{e.args.inspect} )"
end
Btw: the same works in Java, only there you'd probably catch
NullPointerException.
Regards
robert
Robert Klemme Guest
-
dhtapp #5
Re: Messages to nil
Wow, apparently so! Thanks!
- dan
"Reimer Behrends" <behrends@cse.msu.edu> wrote in message
news:slrnbr1tqv.kts.behrends@ellington.cse.msu.edu ...
>
> def nil.method_missing(*args) nil end
>
> do what you want?
>
> Reimer Behrends
dhtapp Guest



Reply With Quote

