From: Rob Biedenharn Date: 2008-10-16T23:41:10+09:00 Subject: Re: symbol confusions!! On Oct 16, 2008, at 9:31 AM, Jay Pangmi wrote: > Rob Biedenharn wrote: >> >> 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 > > Thanks Rob you made my life lot easier.. no I don't have that book I > just have 'Agile Web Development with Rails 2nd Edt.' so, ruby is > just a > small part here and hence internet has been my only source. > Also I confusion about the use of slashes: > %r{(\d{1,2}):(\d{1,2}):(\d{4})} > whats the use of forward slash here > and the '+' sign below: > split(/[^0-9]+/) > Also I think I've seen the use of other words with '%' like %w but I > don't remember which words in particular. > > Thanks. Brian's and Fred's responses should help, too (esp. the link to the earlier Pickaxe) The \d is an escape within a regular expression that's equivalent to [0-9] and + is like {1,} in regular expressions to match "one or more of...". x+ is xx* or x{1,} /[^0-9]+/ is a sequence of one or more non-digits. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com