Irb and Ruby Separation

  • Thread starter Nicholas Van Weerdenburg
  • Start date
N

Nicholas Van Weerdenburg

I've been wondering about why are irb and ruby separate programs.

Python combines the two concepts in its main executable, and I was
wondering if there was a benefit to separating them.

Thanks,
Nick
 
G

Gennady Bystritksy

Nicholas said:
I've been wondering about why are irb and ruby separate programs.

Python combines the two concepts in its main executable, and I was
wondering if there was a benefit to separating them.

Thanks,
Nick

They are not. irb is a ruby program. Here's the content of
/usr/local/bin/irb:

#!/usr/local/bin/ruby
#
# irb.rb - intaractive ruby
# $Release Version: 0.7.3 $
# $Revision: 1.2 $
# $Date: 2002/11/19 02:00:18 $
# by Keiju ISHITSUKA([email protected])
#

require "irb"

if __FILE__ == $0
IRB.start(__FILE__)
else
# check -e option
if /^-e$/ =~ $0
IRB.start(__FILE__)
else
IRB.setup(__FILE__)
end
end

Gennady.
 
F

Florian Gross

Nicholas said:
I've been wondering about why are irb and ruby separate programs.

The benefit is that IRB is a Ruby program, making it easier to patch it
or to do funky stuff. (Like I've done with the Breakpoint library.)

I think it is a good thing to get above the C level whenever you can.
There's a downside of course: IRB needs to re implement some of the
functionality that Ruby already has. (It needed to implement it's own
Lexer, for example, nowadays it could use Ripper instead, but it would
still need to find out whether an expression is already finished or not.)
 
N

Nicholas Van Weerdenburg

Thanks.

I guess my question might be better phrased "why doesn't running the
ruby interpreter with no input not default to interactive mode (irb)
such as with the python interpreter".

I'm mostly curious for no practical reason. Just wondering if there is
functionality or design benefits.
 
N

Nikolai Weibull

* Nicholas Van Weerdenburg (Jan 14, 2005 22:20):
I guess my question might be better phrased "why doesn't running the
ruby interpreter with no input not default to interactive mode (irb)
such as with the python interpreter".

It interprets stdin instead. irb is a completely separate project from
bin/ruby. It's much the same as the shell is separate from the kernel;
an idea that seems to have been foregone by the Python developers.
nikolai
 
D

Dimitri Aivaliotis

* Nicholas Van Weerdenburg (Jan 14, 2005 22:20):

It interprets stdin instead. irb is a completely separate project from
bin/ruby. It's much the same as the shell is separate from the kernel;
an idea that seems to have been foregone by the Python developers.
nikolai
Cool:

[shell prompt] ruby
puts "Hello, world!"
^D
Hello, world!
[shell prompt]

So, in effect it does essentially what's needed - just no shell-like
interface, or any of the other benefits of irb.

- Dimitri
 
N

nobu.nokada

Hi,

At Sat, 15 Jan 2005 06:15:33 +0900,
Nicholas Van Weerdenburg wrote in [ruby-talk:126498]:
I guess my question might be better phrased "why doesn't running the
ruby interpreter with no input not default to interactive mode (irb)
such as with the python interpreter".

I'm mostly curious for no practical reason. Just wondering if there is
functionality or design benefits.

It's in the ToDo list.

* Built-in Interactive Ruby.


Index: ruby.c
===================================================================
RCS file: /cvs/ruby/src/ruby/ruby.c,v
retrieving revision 1.94
diff -U2 -p -r1.94 ruby.c
--- ruby.c 24 Sep 2004 05:53:41 -0000 1.94
+++ ruby.c 15 Jan 2005 05:34:34 -0000
@@ -782,5 +782,15 @@ proc_options(argc, argv)
}
else if (strlen(script) == 1 && script[0] == '-') {
- load_stdin();
+ if (!do_check && !do_loop && isatty(0) && isatty(1) && isatty(2) &&
+ !NIL_P(rb_rescue2(rb_require, (VALUE)"irb",
+ (VALUE (*)())0, (VALUE)0,
+ rb_eLoadError, (VALUE)0))) {
+ require_libraries();
+ ruby_eval_tree = NEW_CALL(NEW_LIT(rb_const_get(rb_cObject, rb_intern("IRB"))),
+ rb_intern("start"), 0);
+ }
+ else {
+ load_stdin();
+ }
}
else {
 
C

Csaba Henk

Hi,

At Sat, 15 Jan 2005 06:15:33 +0900,
Nicholas Van Weerdenburg wrote in [ruby-talk:126498]:
I guess my question might be better phrased "why doesn't running the
ruby interpreter with no input not default to interactive mode (irb)
such as with the python interpreter".

I'm mostly curious for no practical reason. Just wondering if there is
functionality or design benefits.

It's in the ToDo list.

* Built-in Interactive Ruby.

I guess this transition mainly boils down to changing the parser/lexer
used in irb (written in ruby) to the one used within ruby itself, doesn't
it?

Csab
 
N

Nikolai Weibull

* Csaba Henk (Jan 15, 2005 13:40):
I guess this transition mainly boils down to changing the parser/lexer
used in irb (written in ruby) to the one used within ruby itself,
doesn't it?

Eh, the transition mainly boils down to the patch that was included,
right?
nikolai
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top