Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

Consult the Console

Day to day life-shortening experiences
My current project is the biggest thing i had ever did, concerning web applications of course (i leave out my origami career).
We have two dedicated servers, 95 models, 45 high powered DRY controllers , a half-operational BackgroundDRb actions, a whole galaxy of multi-asserted tests, test-cases and a functional hell.
A pack of gems, half a dozen plugins and pack of nead to death programmers.
Not that we needed all that for the project, but once you get into a serious programming frenzy, the tendency is to push it as far as you can.

The only thing worrying me was the debugging part, there is nothing in the world more helpless, irresponsible and depraved than a men in the depth of a debugging binge. I noticed that most of my guys aren't using the real powers of the IRB god, and even more, they are not even aware to the hell that can be unleashed when using...

the script/console..


Ok Ok, how?
The console is a simple, command lined interface to your application on any desired environment (specified as a parameter). Using the console you can try your relation in a less pre-defined way then the Testing mechanisem.
simply run script/console in your application root, you will get a very innocent looking command line entry marker, just waiting for you to unleash the beast within... so... why keep it waiting?

Tough love
One thing about the console, it's output is simply readable once used right. Example.

>> first = "i like"
"i like"
>> second = "bananas!"
"bananas!"
>> first + " " + second
"i like bananas!"


gee, this was fun... no?
never mind, the console is primarily used (by me at least) on Models, it enables you to play with your smelly database creatures, without hitting the refresh button on your browser like some kind of a disordered coffee machine... do i smell an example again?

>> elad = SuperHero.find(:first, :conditions => "very_hansom is TRUE")

#"elad", "IQ"=>"7"}>
>> elad.respond_to?(:fly_to) # Just checking if our superhero can fly
true # alright! my very own flying superhero!
>> elad.fly_to("Liverpool") # Mercy-side here i come!
>> elad.location
"Liverpool"

ok, you got the idea.
I Consider myself to be rather a lazy programmer and in fact a person. I found a few other situations where the Rails console might come handy.

Going on a date!

i wanted to check when will one of my packages arrives to it's destination, the nice clerk told me that it will take about 3 weeks before it will get there.
damn, my mathematical skills are weaker even when being compared to my x-ray vision skills. so i immediatly called my favorite problem solver... the console

>> when will my package arrive to destination? # it will never work, just trying :)
SyntaxError: compile error
(irb):1: syntax error, unexpected kWHEN
when will my package arrive to destination?
^
from (irb):1 # Damn :)
>> 3.weeks.from_now
Thu Apr 05 17:54:22 IDT 2007


yippie!, i immediatly called my Samoan clients and to wait for their next gun shipment on april 5th.

Just kidding :), but isn't it beautiful?

0 comments:


The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels