Hi,
i think i have asked this ~a year or so ago already,
roughly (and in a much shorter form). This is my last try at
it, it is in my todo list, but I now want to either
solve it, or remove it from my todo list
My basic wish is the following:
Since i sometimes copy-paste commented code straight
into irb, I want to toggle “comment reading” on and
off, so i can text long snippets of commented
code from some .rb file straight into IRB to
see what changes i did, but without removing the
leading # comments. I want IRB to do that
comment-removing part.
Specifically, before I copy paste a lot of ruby code
into irb, i would like to do something toggle-able, like
toggle_comments()
which would then strip all leading #'s before it is interpreted
~similar to a regex such as:
x = STDIN.gets.gsub(/^[\s#]*/, ‘’)
So basically, I would just like a method like
def toggle_comments
STDIN.gets.gsub(/^[\s#]*/, ‘’)
end
I looked inside lib/ruby/1.8/irb, it is a little bit
complicated (and almost no comments).
Inside
context.rb
I found an @io object that is like so:
@io = ReadlineInputMethod.new
@io = StdioInputMethod.new
(Depends on whether the user has readline, or not.)
Theses classes can be found in:
input-method.rb
And the @io seems to be interpreted by:
ruby-lex.rb
The basic read-in seems to be done via @io.gets and is
then stored in @io.
I looked inside input-method.rb and ruby-lex.rb, but I am kinda at
a loss now … does anyone know how to manipulate the @io
variable or whatever else is used for storing the “string that
the user typed”?
Should I extend class ReadlineInputMethod with a toggle_comment
and use that regex, or maybe there exists some other, easier way
to apply filtering on that IRB @io before it gets interpreted?
Thanks for the reading, I am glad this thing will soon be
out of my todo list either way