Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4391

Re: Learning Ruby advice needed

From Johnny Morrice <spoon@killersmurf.com>
Newsgroups comp.lang.ruby
Subject Re: Learning Ruby advice needed
Date 2011-05-12 11:57 -0500
Organization Service de news de lacave.net
Message-ID <20110512175738.527d2bf8@killersmurf.com> (permalink)
References <5c6d6fdb8d7a3429d3a5031248106dcd@ruby-forum.com> <eb7418c63516e9c79cbc710620c250cb@ruby-forum.com> <8ba796d970e0b9c21bf1335f4111f0fb@ruby-forum.com>

Show all headers | View raw


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.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Learning Ruby advice needed Rubist Rohit <passionate_programmer@hotmail.com> - 2011-05-12 03:54 -0500
  Re: Learning Ruby advice needed Regis d'Aubarede <regis.aubarede@gmail.com> - 2011-05-12 06:10 -0500
    Re: Learning Ruby advice needed Rubist Rohit <passionate_programmer@hotmail.com> - 2011-05-12 11:01 -0500
      Re: Learning Ruby advice needed Johnny Morrice <spoon@killersmurf.com> - 2011-05-12 11:57 -0500
      Re: Learning Ruby advice needed 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 12:52 -0500
        Re: Learning Ruby advice needed Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-05-12 13:30 -0500
        Re: Learning Ruby advice needed Johnny Morrice <spoon@killersmurf.com> - 2011-05-12 14:28 -0500
          Re: Learning Ruby advice needed Hassan Schroeder <hassan.schroeder@gmail.com> - 2011-05-12 14:44 -0500
            Re: Learning Ruby advice needed Stu <stu@rubyprogrammer.net> - 2011-05-12 14:48 -0500
            Re: Learning Ruby advice needed Johnny Morrice <spoon@killersmurf.com> - 2011-05-12 14:49 -0500
          Re: Learning Ruby advice needed Johnny Morrice <spoon@killersmurf.com> - 2011-05-12 19:46 -0500
      Re: Learning Ruby advice needed Stu <stu@rubyprogrammer.net> - 2011-05-12 13:34 -0500
        Re: Learning Ruby advice needed John Mair <jrmair@gmail.com> - 2011-05-13 09:23 -0500
          Re: Learning Ruby advice needed Adam Prescott <adam@aprescott.com> - 2011-05-13 10:02 -0500
  Re: Learning Ruby advice needed Johnny Morrice <spoon@killersmurf.com> - 2011-05-12 09:26 -0500
    Re: Learning Ruby advice needed Josh Cheek <josh.cheek@gmail.com> - 2011-05-12 13:20 -0500
      Re: Learning Ruby advice needed Johnny Morrice <spoon@killersmurf.com> - 2011-05-12 14:43 -0500
  Re: Learning Ruby advice needed jake kaiden <jakekaiden@yahoo.com> - 2011-05-12 15:29 -0500
    Re: Learning Ruby advice needed Alexander McMillan <alexandermcmillan@hotmail.com> - 2011-05-13 01:28 -0500

csiph-web