Last Used Object

Discussion in 'Ruby' started by Marc Heiler, Nov 24, 2006.

  1. Marc Heiler

    Marc Heiler Guest

    Hi,

    Today I have heard that you can use ; in Smalltalk to
    refer to the last used object.
    I could be wrong, but I think this is not possible
    in Ruby.

    If that is the case, does someone know the reason
    for this, or another way to refer to the last
    used object with some kind of "sugar" (like the
    ; in Smalltalk)?

    --
    Posted via http://www.ruby-forum.com/.
    Marc Heiler, Nov 24, 2006
    #1
    1. Advertising

  2. Marc Heiler

    mitchell Guest

    Hi,

    Marc Heiler wrote:
    > Hi,
    >
    > Today I have heard that you can use ; in Smalltalk to
    > refer to the last used object.
    > I could be wrong, but I think this is not possible
    > in Ruby.
    >
    > If that is the case, does someone know the reason
    > for this, or another way to refer to the last
    > used object with some kind of "sugar" (like the
    > ; in Smalltalk)?
    >


    irb> a=10
    => 10
    irb> _
    => 10

    -Mitchell;
    mitchell, Nov 25, 2006
    #2
    1. Advertising

  3. Marc Heiler

    Marc Heiler Guest

    Marc Heiler, Dec 28, 2006
    #3
  4. Marc Heiler

    Phrogz Guest

    Marc Heiler wrote:
    > Does "normal" ruby have this as well, or
    > is this IRB specific?


    It's easier, I think, to find out yourself than it is to ask the
    question :)

    slim:~ gavinkistner$ ruby -e "a=10;p _"
    -e:1: undefined local variable or method `_' for main:Object (NameError)
    Phrogz, Dec 28, 2006
    #4
  5. On Fri, Dec 29, 2006 at 12:10:08AM +0900, Phrogz wrote:
    > Marc Heiler wrote:
    > > Does "normal" ruby have this as well, or
    > > is this IRB specific?

    >
    > It's easier, I think, to find out yourself than it is to ask the
    > question :)
    >
    > slim:~ gavinkistner$ ruby -e "a=10;p _"
    > -e:1: undefined local variable or method `_' for main:Object (NameError)
    >

    OTOH, there is the (evil) perlesque $_.
    ruby -e 'gets and print $_'

    Of course this is not the same thing, and it's set but a group of
    methods, not automatically every time.

    e.g.:
    ruby -e '7; p $_'
    Logan Capaldo, Dec 28, 2006
    #5
  6. Marc Heiler

    Marc Heiler Guest

    "It's easier, I think, to find out yourself than it is to ask the
    question :)"


    Well, I consider it better to ask silly questions AND get the
    reassurance of what I tried, than to assume something on my
    own without ever error-checking whether my grounds are solid
    or shaken in this regard :)

    --
    Posted via http://www.ruby-forum.com/.
    Marc Heiler, Jan 6, 2007
    #6
  7. On 1/7/07, Marc Heiler <> wrote:
    > "It's easier, I think, to find out yourself than it is to ask the
    > question :)"
    >
    >
    > Well, I consider it better to ask silly questions AND get the
    > reassurance of what I tried, than to assume something on my
    > own without ever error-checking whether my grounds are solid
    > or shaken in this regard :)


    Well, i can reassure you, there is nothing like ; in ruby... and it's
    one of the things where i really envy smalltalk :)

    Transcript show: 'Hello, World!'; nl!

    to compensate this, ruby offers two things... a default receiver of
    your messages (self) and simple chaining of methods (without tons of
    parenthesis)

    print "Hello World".split.join(", ") << "!\n"

    only fooling around of course, something like ; would really be nifty :|
    Michael Fellinger, Jan 7, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    673
  2. Michael Yanowitz

    Last used directory?

    Michael Yanowitz, Jul 12, 2006, in forum: Python
    Replies:
    1
    Views:
    308
    Steven D'Aprano
    Jul 12, 2006
  3. sangram
    Replies:
    16
    Views:
    1,955
  4. Johny
    Replies:
    8
    Views:
    371
  5. fl
    Replies:
    4
    Views:
    812
Loading...

Share This Page