[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

irb, to learn more...

John Joyce

10/14/2007 9:08:00 PM

Here's an interesting thing you can do in irb:
irb

You can run an instance of irb within irb. How very Ruby!?
In irb you can also do this:

methods

(or my preferred approach...)
methods.sort

irb itself has some interesting abilities.

6 Answers

Ben Bleything

10/14/2007 9:46:00 PM

0

On Mon, Oct 15, 2007, John Joyce wrote:
> You can run an instance of irb within irb. How very Ruby!?

This is cool because it lets you set up a new context if you want to try
something without messing with your current context. I'm sure there are
other uses as well.

I believe you can also give each new one a name and switch between them
at will, but I'm not sure how.

> In irb you can also do this:
>
> methods
>
> (or my preferred approach...)
> methods.sort

The reason is that the top-level context of an IRB session is an Object,
so any method you can call on an object is there.

irb is awesome :D

Ben

Grant Hutchins

10/15/2007 1:15:00 AM

0

On Oct 14, 4:08 pm, John Joyce <dangerwillrobinsondan...@gmail.com>
wrote:
> Here's an interesting thing you can do in irb:
> irb
>
> You can run an instance of irb within irb. How very Ruby!?
> In irb you can also do this:
>
> methods
>
> (or my preferred approach...)
> methods.sort
>
> irb itself has some interesting abilities.

Also you can do irb(object) and then you will be executing code in the
context of that object. In other words, you can jump into a class and
define an instance method on it directly, or jump into an instance and
toy around with its methods and instance variables all within its
context. Ctrl-D kicks you back out to the parent irb instance.

John Joyce

10/15/2007 2:16:00 AM

0


On Oct 14, 2007, at 8:20 PM, Grant Hutchins wrote:

> On Oct 14, 4:08 pm, John Joyce <dangerwillrobinsondan...@gmail.com>
> wrote:
>> Here's an interesting thing you can do in irb:
>> irb
>>
>> You can run an instance of irb within irb. How very Ruby!?
>> In irb you can also do this:
>>
>> methods
>>
>> (or my preferred approach...)
>> methods.sort
>>
>> irb itself has some interesting abilities.
>
> Also you can do irb(object) and then you will be executing code in the
> context of that object. In other words, you can jump into a class and
> define an instance method on it directly, or jump into an instance and
> toy around with its methods and instance variables all within its
> context. Ctrl-D kicks you back out to the parent irb instance.
>
>
There must be a way to jump in and out, leaving it running or not.
For example, start irb.
Then, create two named irb sessions inside it.
You operate at the top level, monitor the two inside irb's...


mortee

10/15/2007 2:36:00 AM

0

John Joyce

10/15/2007 3:11:00 AM

0

well, nobody claimed black magic, just that it is interesting and fun
to play with. Sometimes people forget about the fun interesting
aspects of irb.

mortee

10/15/2007 3:26:00 AM

0