IRb: how to start an interactive ruby session with pre-loaded classes

Shyam picture Shyam · Apr 16, 2010 · Viewed 10k times · Source

As I am going through my journey by adopting the Ruby language, I spend a lot of time inside IRb. It's just fantastic! But, as I am not very aware of it's capabilities, and still a “nubby” with Ruby, I would like to know the following:

  • How can I “flush” the session, without restarting IRb (or is this not possible).
  • How can I configure IRb to load a bunch of source files "hello.rb" and "hello_objects.rb", i.e. at startup? I am heavily working in these and it would be nice to know a short hand to load these classes, without manually typing 'load' for each again.

Answer

Evgeny Shadchnev picture Evgeny Shadchnev · Apr 16, 2010

I'm not sure it's possible to 'flush' a session. However, you can load your classes like this:

irb -r 'hello.rb' -r 'hello_objects.rb'