Ask a Question related to Ruby, Design and Development.
  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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. ...
    5. IP Messages
      Recently, my computer has been bombarded by internet ads. One website claims that microsoft included this ability in their Microsoft XP software...
  3. #2

    Default 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

    http://www.ruby-talk.org/cgi-bin/vfr...37?17391-25625
    http://www.ruby-talk.org/cgi-bin/vfr...21?17655-25795

    (these previous URL use frame)

    http://www.ruby-talk.org/17785


    --

    Guy Decoux
    ts Guest

  4. #3

    Default Re: Messages to nil

    dhtapp (dhtapp@cox.net) wrote:
    [...]
    > 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...)
    Does

    def nil.method_missing(*args) nil end

    do what you want?

    Reimer Behrends
    Reimer Behrends Guest

  5. #4

    Default Re: Messages to nil


    "dhtapp" <dhtapp@cox.net> schrieb im Newsbeitrag
    news:2c6sb.12896$7B2.12145@fed1read04...
    > 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...)

    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

  6. #5

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139