optparse examples

Discussion in 'Ruby' started by Jeff Dickens, Dec 5, 2003.

  1. Jeff Dickens

    Jeff Dickens Guest

    I have a question about the optparse examples at
    http://docs.meg.nu/local-docs/ruby/optparse/optparse.htmlWhat does the
    following do ?if (Fixnum === :)
    class << vars
    def inspect
    "{" + collect {|k,v| ":#{k.id2name}=>#{v.inspect}"}.join(", ") + "}"
    end
    end
    end
    and then this line which is commented out: #opts.variable.each {|sym| puts
    "#{sym} = #{opts.send(sym).inspect}"}Looks like some kind of debug code, but
    I thought if I understood it itshed some light on things in general.
     
    Jeff Dickens, Dec 5, 2003
    #1
    1. Advertising

  2. Jeff Dickens

    Guest

    Hi,

    At Fri, 5 Dec 2003 13:32:05 +0900,
    Jeff Dickens wrote:
    >
    > I have a question about the optparse examples at
    > http://docs.meg.nu/local-docs/ruby/optparse/optparse.html
    > What does the following do ?
    > if (Fixnum === :)
    > class << vars
    > def inspect
    > "{" + collect {|k,v| ":#{k.id2name}=>#{v.inspect}"}.join(", ") + "}"
    > end
    > end
    > end


    In older version, ruby didn't have Symbol class and symbols are
    just Fixnum. The code is to show the hash keys as symbols.

    > and then this line which is commented out: #opts.variable.each {|sym| puts
    > "#{sym} = #{opts.send(sym).inspect}"}Looks like some kind of debug code, but
    > I thought if I understood it itshed some light on things in general.


    Eariest OptionParser had #variable method, but it has been
    abolished long ago.

    --
    Nobu Nakada
     
    , Dec 8, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Goodger

    Re: Iterating over optparse options

    David Goodger, Jun 25, 2003, in forum: Python
    Replies:
    0
    Views:
    1,010
    David Goodger
    Jun 25, 2003
  2. pascal barbedor

    blanks embedded in python 2.3 optparse

    pascal barbedor, Jul 29, 2003, in forum: Python
    Replies:
    3
    Views:
    337
    =?ISO-8859-2?Q?Nagy_L=E1szl=F3_Zsolt?=
    Jul 29, 2003
  3. GMTaglia

    optparse examples

    GMTaglia, Oct 17, 2004, in forum: Python
    Replies:
    4
    Views:
    522
    GMTaglia
    Oct 18, 2004
  4. Mark Wilson
    Replies:
    1
    Views:
    138
    Takashi & Kayoko Sano
    Sep 4, 2003
  5. Ara.T.Howard

    more optparse examples...

    Ara.T.Howard, Dec 18, 2003, in forum: Ruby
    Replies:
    0
    Views:
    138
    Ara.T.Howard
    Dec 18, 2003
Loading...

Share This Page