Blog
what did i learn today
Uncategorized ruby strings
use %q to create strings

In my gemspec created by jeweler I saw string creating using %Q. What? [ruby] gem.summary = %Q{TODO: one-line summary of your gem} gem.description = %Q{TODO: longer description of your gem} [/ruby] I found a pagedescribing ruby string creation, and it seems %Q is the equivalent of double quote delimited strings and %q is the equivalent of single quotes. While i was pondering what the advantage could be of writing it that way, i opened up irb and look and behold: [ruby] irb(main):001:0> test = %Q{ggg gggg ggg} => "ggg gggg ggg" irb(main):002:0> test2= "ff ff ff" => "ff ff ff" irb(main):003:0> test= %Q{%q{ffff ffff ffff}} => "%q{ffff ffff ffff}" irb(main):004:0> test= %Q{this is a "test", curious whether 'it' works :)} => "this is a "test", curious whether 'it' works :)" irb(main):005:0> test= %Q{this is a "test", i am curious whether #{test2} 'it' works :)} => "this is a "test", i am curious whether ff ff ff 'it' works :)" irb(main):006:0> [/ruby] Cool! It allows you to write your strings without having to think about escaping the quotes.

More ...