Last Used Object

M

Marc Heiler

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)?
 
M

mitchell

Hi,

Marc said:
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;
 
P

Phrogz

Marc said:
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)
 
L

Logan Capaldo

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

Marc Heiler

"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 :)
 
M

Michael Fellinger

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top