[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

IRB and Filtering Input?

Marc Heiler

9/16/2006 1:59:00 PM

Hi,

Is there a way to filter what is typed/copy-pasted in/into IRB?

For example, just for fun and showcasing, to strip any 'a'
character typed when you are in IRB.

Or, more importantly and main reason to post this, to replace
leading whitespace + the first '#' char - so that a ruby
command, that is normally "protected" as a # comment,
is run instead.

I'd like to have a simple method to toggle between these
"modes", i.e.
filter_on
filter_off
or similar,
and then copy paste some lines of codes.

Right now I manually remove the leading #
and I'd like to let IRB handle this
rather :)


--
Posted via http://www.ruby-....

4 Answers

Paul Lutus

9/16/2006 4:08:00 PM

0

Marc Heiler wrote:

> Hi,
>
> Is there a way to filter what is typed/copy-pasted in/into IRB?

To solve this problem, write your own front end for "Kernel::eval" instead
of irb. With a few lines of code, you would have total control over what
"eval" saw and acted upon.

--
Paul Lutus
http://www.ara...

Jeff Schwab

9/16/2006 6:50:00 PM

0

Marc Heiler wrote:
> Hi,
>
> Is there a way to filter what is typed/copy-pasted in/into IRB?
>
> For example, just for fun and showcasing, to strip any 'a'
> character typed when you are in IRB.
>
> Or, more importantly and main reason to post this, to replace
> leading whitespace + the first '#' char - so that a ruby
> command, that is normally "protected" as a # comment,
> is run instead.
>
> I'd like to have a simple method to toggle between these
> "modes", i.e.
> filter_on
> filter_off
> or similar,
> and then copy paste some lines of codes.
>
> Right now I manually remove the leading #
> and I'd like to let IRB handle this
> rather :)

Warning: This is a complete cop-out, and does not answer your question.

If you're using Vim, you can copy only the columns of text after some
leading characters (e.g. #\s*) by copying only a block selected with
Control-V.

Suraj Kurapati

9/16/2006 6:52:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marc Heiler wrote:
> Is there a way to filter what is typed/copy-pasted in/into IRB?
>
> For example, just for fun and showcasing, to strip any 'a'
> character typed when you are in IRB.
>
> Or, more importantly and main reason to post this, to replace
> leading whitespace + the first '#' char - so that a ruby
> command, that is normally "protected" as a # comment,
> is run instead.

>> eval STDIN.read.gsub(/^[\s#]*/, '')
puts "yes"
## # puts "no, no, no!"
yes
no, no, no!
=> nil


Note that I just copied & pasted some code and then pressed
Control-D to signal that I've finished typing my code.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFFDEd2mV9O7RYnKMcRAmvNAJwMtZkFdbME3kfyVQODSntTdqnKdwCeKkyx
GXNvW9CtJhBSM2WnE255Pys=
=YM2c
-----END PGP SIGNATURE-----

Marc Heiler

9/16/2006 10:03:00 PM

0

Ok thanks for the helping seed points guys :)

--
Posted via http://www.ruby-....