optparse examples

J

Jeff Dickens

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.
 
N

nobu.nokada

Hi,

At Fri, 5 Dec 2003 13:32:05 +0900,
Jeff said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top