# IRB and Filtering Input?

**URL:** <https://www.ruby-forum.com/t/irb-and-filtering-input/68905>\
**Category:** Ruby\
**Created:** [September 16, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/irb-and-filtering-input/68905 "2006-09-16T15:58:24Z")\
**Posts on this page:** 4\
**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:** [September 16, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/irb-and-filtering-input/68905/1 "2006-09-16T15:58:24Z")

</div>

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 🙂

---

<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:** [September 16, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/irb-and-filtering-input/68905/2 "2006-09-16T18:12:46Z")

</div>

Marc H. 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.

---

<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:** [September 16, 2006, 8:50pm UTC](https://www.ruby-forum.com/t/irb-and-filtering-input/68905/3 "2006-09-16T20:50:56Z")

</div>

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

Marc H. 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-----

---

<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:** [September 17, 2006, 12:02am UTC](https://www.ruby-forum.com/t/irb-and-filtering-input/68905/4 "2006-09-17T00:02:08Z")

</div>

Ok thanks for the helping seed points guys 🙂
