In the cucumber rake task I see this construct: t.rcov_opts = %w{--rails --exclude lib\/ruby,lib64\/ruby,\/usr,osx\/objc,gems\/,test\/,spec\/,features\/} t.rcov_opts << %[--output "coverage"] My questions is: What do %w and % represent with respect to the "block"? in the first case and the "array"? in the second? I cannot find an explanation of either usage in the documentation. -- Posted via http://www.ruby-forum.com/.
w% is a ruby notation. It creates an Array of of the literal string you type separated by white space Emmanuel On Feb 3, 2009, at 10:49 AM, James Byrne wrote:> In the cucumber rake task I see this construct: > > t.rcov_opts = %w{--rails --exclude > lib\/ruby,lib64\/ruby,\/usr,osx\/objc,gems\/,test\/,spec\/,features\/} > t.rcov_opts << %[--output "coverage"] > > My questions is: What do %w and % represent with respect to the > "block"? in the first case and the "array"? in the second? I cannot > find an explanation of either usage in the documentation. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Explanation: http://jimhoskins.com/2008/10/07/ruby-percent-syntax-percent-functions/ Ngoc. On Wed, Feb 4, 2009 at 3:56 AM, Emmanuel Pinault <seatmanu at gmail.com> wrote:> w% is a ruby notation. It creates an Array of of the literal string you > type separated by white space > > Emmanuel > > On Feb 3, 2009, at 10:49 AM, James Byrne wrote: > > In the cucumber rake task I see this construct: >> >> t.rcov_opts = %w{--rails --exclude >> lib\/ruby,lib64\/ruby,\/usr,osx\/objc,gems\/,test\/,spec\/,features\/} >> t.rcov_opts << %[--output "coverage"] >> >> My questions is: What do %w and % represent with respect to the >> "block"? in the first case and the "array"? in the second? I cannot >> find an explanation of either usage in the documentation. >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090204/8b93ceb9/attachment.html>
On Tue, Feb 3, 2009 at 12:49 PM, James Byrne <lists at ruby-forum.com> wrote:> In the cucumber rake task I see this construct: > > t.rcov_opts = %w{--rails --exclude > lib\/ruby,lib64\/ruby,\/usr,osx\/objc,gems\/,test\/,spec\/,features\/} > t.rcov_opts << %[--output "coverage"] > > My questions is: What do %w and % represent with respect to the > "block"? in the first case and the "array"? in the second? I cannot > find an explanation of either usage in the documentation.They''re not really a block and an array - the %w can be followed by the delimiter of your choice, and makes an array of the words between the first and next instance of that delimiter. For example, each of these: %w{these words} %w[these words] %w|these words| %w%these words% ... all produce this array: ["these","words"] HTH, David> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
%w<delim><string><delim> == string.split(/\s+/) (maybe not exactly that regexp, but basically it''s an array of the words--hence the w) %<delim><string><delim> == string, but without needing to escape the quotes. It''s the same as using %Q (ie, it understands escape sequences and interpolated expressions inside, while %q is a literal string) HTH -foca On Tue, Feb 3, 2009 at 4:49 PM, James Byrne <lists at ruby-forum.com> wrote:> In the cucumber rake task I see this construct: > > t.rcov_opts = %w{--rails --exclude > lib\/ruby,lib64\/ruby,\/usr,osx\/objc,gems\/,test\/,spec\/,features\/} > t.rcov_opts << %[--output "coverage"] > > My questions is: What do %w and % represent with respect to the > "block"? in the first case and the "array"? in the second? I cannot > find an explanation of either usage in the documentation. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Emmanuel Pinault wrote:> w% is a ruby notation. It creates an Array of of the literal string > you type separated by white space > > EmmanuelThank you. What does %[...] do? -- Posted via http://www.ruby-forum.com/.
James Byrne wrote:> > Thank you. What does %[...] do?This would not happen to be the same thing as %Q[..] would it? -- Posted via http://www.ruby-forum.com/.
On Tue, Feb 3, 2009 at 1:10 PM, James Byrne <lists at ruby-forum.com> wrote:> James Byrne wrote: >> >> Thank you. What does %[...] do? > > This would not happen to be the same thing as %Q[..] would it?Nope. http://www.rubycentral.com/pickaxe/tut_stdtypes.html scroll down to strings> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Could not remember that one but based on testing on irb, seems to do the reverse :) Array to string. so %[test blah] becomes "test blah" On Feb 3, 2009, at 11:04 AM, James Byrne wrote:> Emmanuel Pinault wrote: >> w% is a ruby notation. It creates an Array of of the literal string >> you type separated by white space >> >> Emmanuel > > Thank you. What does %[...] do? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
James Byrne wrote:> > This would not happen to be the same thing as %Q[..] would it?Apparently, the construct: t.rcov_opts = %w{--rails --exclude lib\/ruby,lib64\/ruby,\/usr,osx\/objc,gems\/,test\/,spec\/,features\/} t.rcov_opts << %[--output "coverage"] is equivalent to: t.rcov_opts = [ "--rails" "--exclude" "lib\/ruby,lib64\/ruby,\/usr,osx\/objc,gems\/,test\/,spec\/,features\/" "--output" "coverage" ] Posted so that I can google for it next time. -- Posted via http://www.ruby-forum.com/.
A full listing of this stuff can be found here: http://www.zenspider.com/Languages/Ruby/QuickRef.html#6 % appears to be the same thing as %Q On Tue, Feb 3, 2009 at 1:10 PM, James Byrne <lists at ruby-forum.com> wrote:> James Byrne wrote: > > > > Thank you. What does %[...] do? > > This would not happen to be the same thing as %Q[..] would it? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090203/e777c84d/attachment.html>
David Chelimsky wrote:> On Tue, Feb 3, 2009 at 1:10 PM, James Byrne <lists at ruby-forum.com> > wrote: >> James Byrne wrote: >>> >>> Thank you. What does %[...] do? >> >> This would not happen to be the same thing as %Q[..] would it? > > Nope. > > http://www.rubycentral.com/pickaxe/tut_stdtypes.html > > scroll down to stringsI did. I can find nothing that discusses the %[] construct. -- Posted via http://www.ruby-forum.com/.
Uh, seems my email never arrived? This is what I had written: %w<delim><string><delim> == string.split(/\s+/) (maybe not exactly that regexp, but basically it''s an array of the words--hence the w) %<delim><string><delim> == string, but without needing to escape the quotes. It''s the same as using %Q (ie, it understands escape sequences and interpolated expressions inside, while %q is a literal string) HTH -foca On Tue, Feb 3, 2009 at 5:52 PM, James Byrne <lists at ruby-forum.com> wrote:> David Chelimsky wrote: >> On Tue, Feb 3, 2009 at 1:10 PM, James Byrne <lists at ruby-forum.com> >> wrote: >>> James Byrne wrote: >>>> >>>> Thank you. What does %[...] do? >>> >>> This would not happen to be the same thing as %Q[..] would it? >> >> Nope. >> >> http://www.rubycentral.com/pickaxe/tut_stdtypes.html >> >> scroll down to strings > > I did. I can find nothing that discusses the %[] construct. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >