[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Last Used Object

Marc Heiler

11/24/2006 11:12:00 PM

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-....

6 Answers

mitchell

11/25/2006 12:31:00 AM

0

Marc Heiler

12/28/2006 3:04:00 PM

0

Very cool

Does "normal" ruby have this as well, or
is this IRB specific?

--
Posted via http://www.ruby-....

Gavin Kistner

12/28/2006 3:08:00 PM

0

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)

Logan Capaldo

12/28/2006 6:30:00 PM

0

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 $_'


Marc Heiler

1/6/2007 11:50:00 PM

0

"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-....

Michael Fellinger

1/7/2007 2:29:00 AM

0

On 1/7/07, Marc Heiler <shevegen@linuxmail.org> 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 :|