PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Using irb as a REPL
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Using irb as a REPL

Réponse
 
LinkBack Outils de la discussion
Vieux 19/11/2007, 23h21   #1
S. Robert James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Using irb as a REPL

Lisp programmers often use the REPL (similar to IRB) as a simple way
to make an interactive interface to their app. I'd like to do the
same thing with irb - that is, define my classes, and load irb in the
context.

I can get about half way there:

require 'irb'
IRB.start
my_class = MyClass.new(...) # I want this to be the context
irb my_class

....works, but you have to type "quit" to load. Is there a better way
to leverage IRB from within my code? What do the Ruby hackers say? (I
know a lot have a Lisp background, and so wouldn't want Ruby to not
have a REPL shell...)
  Réponse avec citation
Vieux 19/11/2007, 23h33   #2
S. Robert James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using irb as a REPL

On Nov 19, 6:21 pm, "S. Robert James" <srobertja...@gmail.com> wrote:
> Lisp programmers often use the REPL (similar to IRB) as a simple way
> to make an interactive interface to their app. I'd like to do the
> same thing with irb - that is, define my classes, and load irb in the
> context.
>
> I can get about half way there:
>
> require 'irb'
> IRB.start
> my_class = MyClass.new(...) # I want this to be the context
> irb my_class
>
> ...works, but you have to type "quit" to load. Is there a better way
> to leverage IRB from within my code? What do the Ruby hackers say? (I
> know a lot have a Lisp background, and so wouldn't want Ruby to not
> have a REPL shell...)


Another, similar problem with the above:
irb my_class
conf.prompt_mode = :SIMPLE # This line is ignored
  Réponse avec citation
Vieux 20/11/2007, 02h07   #3
Cameron McBride
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using irb as a REPL

On 11/19/07, S. Robert James <srobertjames@gmail.com> wrote:
> On Nov 19, 6:21 pm, "S. Robert James" <srobertja...@gmail.com> wrote:
> > Lisp programmers often use the REPL (similar to IRB) as a simple way
> > to make an interactive interface to their app. I'd like to do the
> > same thing with irb - that is, define my classes, and load irb in the
> > context.
> >
> > I can get about half way there:
> >
> > require 'irb'
> > IRB.start
> > my_class = MyClass.new(...) # I want this to be the context
> > irb my_class
> >
> > ...works, but you have to type "quit" to load. Is there a better way
> > to leverage IRB from within my code? What do the Ruby hackers say? (I
> > know a lot have a Lisp background, and so wouldn't want Ruby to not
> > have a REPL shell...)

>
> Another, similar problem with the above:
> irb my_class
> conf.prompt_mode = :SIMPLE # This line is ignored


hmmm, I've also had some problems trying to add a command interface to
some code. I found trying to bend IRB to fit the needs seems to be
trickier than just coding up a solution in readline directly. Is that
really the best solution?

Cameron

  Réponse avec citation
Vieux 20/11/2007, 02h26   #4
S. Robert James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using irb as a REPL

On Nov 19, 9:07 pm, Cameron McBride <cameron.mcbr...@gmail.com> wrote:
>
> hmmm, I've also had some problems trying to add a command interface to
> some code. I found trying to bend IRB to fit the needs seems to be
> trickier than just coding up a solution in readline directly. Is that
> really the best solution?
>
> Cameron


Then you miss out on the full power of Ruby in your interface!
The beauty of using a REPL or IRB is that you have an easy command
line interface, with automatic scripting when you need it, expandable
to the full power of the host language as needed.
  Réponse avec citation
Vieux 20/11/2007, 02h47   #5
Cameron McBride
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using irb as a REPL

On 11/19/07, S. Robert James <srobertjames@gmail.com> wrote:
> On Nov 19, 9:07 pm, Cameron McBride <cameron.mcbr...@gmail.com> wrote:
> >
> > hmmm, I've also had some problems trying to add a command interface to
> > some code. I found trying to bend IRB to fit the needs seems to be
> > trickier than just coding up a solution in readline directly. Is that
> > really the best solution?
> >
> > Cameron

>
> Then you miss out on the full power of Ruby in your interface!
> The beauty of using a REPL or IRB is that you have an easy command
> line interface, with automatic scripting when you need it, expandable
> to the full power of the host language as needed.


Sorry, I wasn't clear. I'm talking about building a ruby library and
then the CLI with readline does a stateful eval. Problem is that it
reimplements functionality that already exists in IRB.

Cameron

  Réponse avec citation
Vieux 20/11/2007, 03h42   #6
_why
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using irb as a REPL

On Tue, Nov 20, 2007 at 08:25:00AM +0900, S. Robert James wrote:
> Lisp programmers often use the REPL (similar to IRB) as a simple way
> to make an interactive interface to their app. I'd like to do the
> same thing with irb - that is, define my classes, and load irb in the
> context.


There's an example of this in Shoes:

http://code.whytheluckystiff.net/svn...samples/irb.rb

The MimickIRB class just wraps IRB's RubyLex class in a very simple
REPL. I don't know if this is exactly what you're looking for
(since it doesn't do debugging, .irbrc, or frames) but it's nice if
you want to start your own from nothing.

_why

  Réponse avec citation
Vieux 20/11/2007, 20h05   #7
Giles Bowkett
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using irb as a REPL

On 11/19/07, S. Robert James <srobertjames@gmail.com> wrote:
> Lisp programmers often use the REPL (similar to IRB) as a simple way
> to make an interactive interface to their app. I'd like to do the
> same thing with irb - that is, define my classes, and load irb in the
> context.


There's one very simple way to do this. Do

gem install aws-s3

And have a look at s3sh in the bin dir. It's basically just a shell
script. It just aims regular old IRB at a setup file which establishes
some relevant variables and loads some relevant modules.

Rails console does nearly exactly the same thing - all it really adds
in is more libraries and some command-line args with optparse.

--
Giles Bowkett

Podcast: http://hollywoodgrit.blogspot.com
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com

  Réponse avec citation
Vieux 29/11/2007, 21h36   #8
Joel VanderWerf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using irb as a REPL

S. Robert James wrote:
> Lisp programmers often use the REPL (similar to IRB) as a simple way
> to make an interactive interface to their app. I'd like to do the
> same thing with irb - that is, define my classes, and load irb in the
> context.
>
> I can get about half way there:
>
> require 'irb'
> IRB.start
> my_class = MyClass.new(...) # I want this to be the context
> irb my_class
>
> ...works, but you have to type "quit" to load. Is there a better way
> to leverage IRB from within my code? What do the Ruby hackers say? (I
> know a lot have a Lisp background, and so wouldn't want Ruby to not
> have a REPL shell...)


This might :

http://blade.nagaokaut.ac.jp/cgi-bin...by-talk/244139

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h29.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18825 seconds with 16 queries