Ruby Interactive Prompt


I just discovered a couple of days ago that this amazing online ruby interactive prompt is a 200,000+ line monster of code! And, more importantly, it’s down.

I never understood how to write a prompt like that; a little experimentation resulted in this code, which works (more or less) the same (minus the demo/tutorial material):

def show_prompt
putc "\n" # blank line improves readability
putc ">"
putc " "
end

show_prompt
input = gets

while(true)
begin
puts eval(input)
rescue StandardError => e
puts "Error: " + e
end

show_prompt
input = gets
end

Easy as that! And, as you’d expect, everything stays in scope, so you can do whatever you please.

Tags: , ,     Posted in Development

Rate this article:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Related Content


Leave a Reply