From: Rob Biedenharn Date: 2008-10-16T21:44:09+09:00 Subject: Re: symbol confusions!! On Oct 16, 2008, at 8:07 AM, Jay Pangmi wrote: > Hi, I'm new to ruby and I'm going thru pretty good as I've done java > but > the only thing, at this point, thats really bothering me is the use of > symbols like: > %w{} > %r{} > %7d etc etc.. > > So, is there anywhere I can find good discussions about such symbols > coz > until now I'm using it blindly... thanks Do you have a book like the Pickaxe?[1] That will go into great detail on all the features that Ruby has to offer. Briefly, however: %w{} is a way to turn a list of words into an array: %w{ one fish two fish } => [ "one", "fish", "two", "fish" ] %r{} is a regular expression literal. %r{stuff.*} is like /stuff.*/ without having to quote slashes (which is the main reason to see it used if you're matching a file path, for example) %7d is probably a format specification from Kernel#sprintf or String#% meaning a decimal value in a minimum of 7 columns: "%7d"%42 => " 42" Oh, and "Kernel#sprintf" (generally, ClassName#method) means the instance method 'sprintf' from the class (or module) 'Kernel' (so, the '%' method from the String class). -Rob [1] http://www.pragprog.com/titles/ruby/programming-ruby Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com