tags:

views:

40

answers:

2

Hi, I need an interactive environment to play with some algorithm stuff. I want to be able to view what's been defined (data, function) so far and be able save/load so I can continue from a previous saved snapshot if something went wrong. Since I chose ruby as my main scripting language, I hope it had these features built in.

If ruby interactive mode does not provide these functionality, what else you recommend for that?

Thanks

+1  A: 

So here’s a technique that will append commands entered in your IRB session to a file in your home directory (idea from ruby-talk:58931). Put the following in your .irbrc:

module Readline
  module History
    LOG = "#{ENV['HOME']}/.irb-history"

    def self.write_log(line)
      File.open(LOG, 'ab') {|f| f << "#{line}
"}
    end

    def self.start_session_log
      write_log("
# session start: #{Time.now}

")
      at_exit { write_log("
# session stop: #{Time.now}
") }
    end
  end

  alias :old_readline :readline
  def readline(*args)
    ln = old_readline(*args)
    begin
      History.write_log(ln)
    rescue
    end
    ln
  end
end

Readline::History.start_session_log
ennuikiller
This is not what I was looking for. I don't want to dig into my input history to find out what I've done to the current session. But thanks for showing me a hack to do history capturing.
Codism
A: 

You should check out the sketches gem which let's you prototype code in a temporary file in your preferred editor. I don't think it supports snapshots.

In irb I would use it as follows:

>> sketch
# Write some code in an editor ...

# Lists sketches and their code
>> sketches

# Reopens the first sketch from above
>> sketch 1

If you want a more powerful interactive prototyping environment, see boson.

Just came back from cinemark. You guys should see the movie. Roland just setup a new standard! Will try sketch and boson later.
Codism