From: "Ara.T.Howard" Date: 2004-08-06T23:22:08+09:00 Subject: Re: %w for symbols On Fri, 6 Aug 2004, Austin Ziegler wrote: > On Fri, 6 Aug 2004 20:21:25 +0900, Florian Gross wrote: >> Austin Ziegler wrote: >>> It seems common enough that it might be nice to have this. Perhaps >>> %W{} instead of %w{} ? >> %W{} is already taken: >> >> irb(main):006:0> %W{1 #{1+1} 3} >> => ["1", "2", "3"] >> irb(main):007:0> %w{1 #{1+1} 3} >> => ["1", "#{1+1}", "3"] >> >> And I think that [:foo, :bar, :qux] is already short enough. > > Ah, but (to use Gavin's suggested form): > > %s(1 2 3) is shorter than [:"1", :"2", :"3"] for any given version. > > I don't know how often I'd use this -- I rarely even use %w{} (and > didn't even know about %W{}), except in unit tests. It seems like a > good idea, though. i use them both in almost every program - and would like to see a symbol version too - but i'm wondering if the OP has noticed that symbols might not even be needed 'foobar'.send 'index', 'f' => 0 what i mean is - alot of things that take symbols also take strings. in my opinion this is as it should be since yaml makes pulling string data into a program so trivial. since i've started using it everywhere i use symbols less and less and try to write my own code using the following approach class Klass def method args, opts = {} foobar = getopt opts, :foobar end def getopt hash, opt hash[opt] || hash["#{ opt }.intern] || hash[#{ opt }] end end so the string/symbol equiv will hold. anyhow, just thought i'd point out that a list of symbols may or may not actually be needed... i'd vote for the %s( foo bar baz ) idea cheers. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================