From: James Edward Gray II Date: 2007-08-26T12:17:36+09:00 Subject: Re: IRB module with non-blocking asynchronous gets On Aug 25, 2007, at 3:09 AM, Shane Liesegang wrote: > Is there a way to use the IRB module so that it evaluates code on- > demand > only instead of running in a constant loop? I'm working on my glue code speech for Lone Star Rubyconf today so my first thought was: #!/usr/bin/env ruby -wKU class IRbOnDemand def initialize @irb = IO.popen("irb -f --simple-prompt --noreadline", "r+") end def run(ruby) @irb.puts ruby @irb.flush @irb.each do |line| return eval($1) if line =~ /\A=>\s*(.+)/ end end end irb = IRbOnDemand.new result = irb.run %Q{a = %w[words] * 3} puts "Result: #{result.inspect}" puts "Doing other things..." sleep 3 result = irb.run %Q{a} puts "Result: #{result.inspect}" __END__ Is that what you are after? If it is, do we really need IRb at all? How's this: #!/usr/bin/env ruby -wKU class IRbOnDemand def initialize @binding = binding end def run(ruby) eval ruby, @binding end end irb = IRbOnDemand.new result = irb.run %Q{a = %w[words] * 3} puts "Result: #{result.inspect}" puts "Doing other things..." sleep 3 result = irb.run %Q{a} puts "Result: #{result.inspect}" __END__ James Edward Gray II