NetManiac

Witold Rugowski on web20 wave with Ruby on Rails

I want my console!

Posted on January 17, 2008 - Filed Under Ruby

When I had my first contact with Rails I was astonished. One of the coolest features for me was console. Total control of live application or just live testing. What You want. It must have been similar feeling to operate this console. Total control!

Console, but slightly different
Image from SXC

But best yet to come. I’m writing in Ruby also other applications. Read other – no Rails. In those applications You can have own console, too. Think about it, interactive shell to play with all data objects in Your program. How easy becomes testing ideas (like what would be if I changed that)? And having own console is easier than it seems.

I have looked through Rails console code and it turned out it is only few lines of code. So, here You have recipe for generic console. How to write own console in less than 5 lines of code:

irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'

libs =  " -r irb/completion"
libs << " -r config/setup"
exec "#{irb} #{libs} --simple-prompt"

I have put in my application all config data and require into config/setup. After executing this file with Ruby interpreter You have interactive shell to play with Your application.

Popularity: 5% [?]

Hits for this post: 2531

Similar Posts

Comments

3 Responses to “I want my console!”

  1. Michal Hantl on October 25th, 2008 21:27

    links from Technoratiirb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? ‘irb.bat’ : ‘irb’ libs = ” -r irb/completion” libs << ” -r config/setup” #include vlastního skriptu s aplikací exec “#{irb} #{libs} –simple-prompt” viahttp://nhw.pl/wp/2008/01/17/i-want-my-console

  2. Baz on January 17th, 2008 22:46

    Very nice. I’m sure I’ll find a use for that.

  3. NetManiac on January 18th, 2008 11:00

    I wish I had examined this earlier. Creating console for own application is so easy ;) Ruby has so many nice surprises :)

    I’d saved a lot of time, when debugging my apps

  4. Michal Hantl on October 25th, 2008 21:54

    Thanks for this.

Leave a Reply