On Fri, 13 May 2011 01:01:29 +0900
Rubist Rohit <passionate_programmer / hotmail.com> wrote:

> I don't understand how you all feel so comfortable with "irb". It is 
> good for one line syntax. I want to create a simple Windows app.
> where I want to keep classes in a separate file and UI in another
> file.

Yes, store your code in files.  It's The Way (tm).

But irb lets you inside of your code. 

It's a good way to exploit the reflexive properties of ruby.  

So say we're reinventing pygame and have a file at ui/screen.rb that
looks like this:

class Screen

        # Draw a surface onto this screen
        def blit x, y, surface
                # Unimplemented
        end

        # Flip buffers
        def flip
                # Unimplemented
        end

        # Does this screen support OpenGL?
        def opengl?
                false
        end

end

You can load this into irb like so:

irb(main):001:0> require "./ui/screen"
=> true
irb(main):002:0> win = Screen.new

Then you can tell win to do things, or ask stuff of it.  Like ask what
methods it has.

=> #<Screen:0x00000000a8a278
irb(main):003:0> win.methods

=> [:blit, :flip, :opengl?, :nil?, :=== ........and so on]

Considering you can do that with every single value in ruby, it's
pretty handy, no?

You can ask it what its class is:

irb(main):004:0> puts win.class
Screen
=> nil

Or you could get it to do something you've written.  In this
case it just a query.

irb(main):005:0> puts win.opengl?
false
=> nil

I guess I just find it very handy!  It's not really hugely exciting,
just very useful.