I'm using IRB's Ruby lexer for this so it should in theory not screw you up as badly as the Switch.pm module for Perl 5.
Details and source code are available at http://www.codepaste.org/view/paste/300 -- but the source code and the Binding.of_caller dependency are also attached to this mail.
Maybe this technique can be used for trying out other, more complex modifications of the Ruby language?
"Edgardo Hames" <ehames@gmail.com> schrieb im Newsbeitrag
news:478c16ae041018053737c72bec@mail.gmail.com...
> Moin!
>
> I've implemented a Ruby source code filter for the frequently
requested
> ".=" operator. (Replace by result of method call)
>
> Here's a boring example of how it is used:
>
> #!/usr/bin/ruby -rfilter
> obj = "foobar"
> obj .= reverse
> p obj # => "raboof"
Hi, Florian. How does .= differ from bang methods?
I mean obj.reverse seems to be the same as obj.reverse!
Not quite: the bang method usually saves an intermediate instance *and* it
might have undesirable side effects (if someone else holds a reference to
the instance and doesn't expect it to be modified). As a consequence,
".=" will work with frozen objects, while bang methods usually don't. As
usual it's a tradeoff / design decision which of both approaches you use.
Kind regards
robert
···
On Sat, 16 Oct 2004 09:34:28 +0900, Florian Gross <flgr@ccan.de> wrote: