Last Used Object

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

Hi,

Marc H. wrote:

; in Smalltalk)?

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

-Mitchell;

Very cool

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

Marc H. 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 :slight_smile:

slim:~ gavinkistner$ ruby -e "a=10;p "
-e:1: undefined local variable or method `
’ for main:Object (NameError)

“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 :slight_smile:

On Fri, Dec 29, 2006 at 12:10:08AM +0900, Phrogz wrote:

Marc H. 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 :slight_smile:

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

On 1/7/07, Marc H. [email protected] 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 :slight_smile:

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs