# Last Used Object

**URL:** <https://www.ruby-forum.com/t/last-used-object/77190>\
**Category:** Ruby\
**Created:** [November 25, 2006, 12:11am UTC](https://www.ruby-forum.com/t/last-used-object/77190 "2006-11-25T00:11:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [November 25, 2006, 12:11am UTC](https://www.ruby-forum.com/t/last-used-object/77190/1 "2006-11-25T00:11:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [November 25, 2006, 1:33am UTC](https://www.ruby-forum.com/t/last-used-object/77190/2 "2006-11-25T01:33:50Z")

</div>

Hi,

Marc H. wrote:

> ; in Smalltalk)?

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

-Mitchell;

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 28, 2006, 4:03pm UTC](https://www.ruby-forum.com/t/last-used-object/77190/3 "2006-12-28T16:03:49Z")

</div>

Very cool

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

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 28, 2006, 4:12pm UTC](https://www.ruby-forum.com/t/last-used-object/77190/4 "2006-12-28T16:12:04Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [January 7, 2007, 12:50am UTC](https://www.ruby-forum.com/t/last-used-object/77190/5 "2007-01-07T00:50:14Z")

</div>

“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 🙂

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 28, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/last-used-object/77190/6 "2006-12-28T19:31:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [January 7, 2007, 3:29am UTC](https://www.ruby-forum.com/t/last-used-object/77190/7 "2007-01-07T03:29:45Z")

</div>

On 1/7/07, Marc H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 😑
