Skip to main content

Diigo Home

Ruby Programming/Alternate quotes - Wikibooks, collection of open-content text... - The Diigo Meta page

en.wikibooks.org/...Alternate_quotes - Cached - Annotated View

Benx Shen's personal annotations on this page

benxshen
Benxshen bookmarked on 2009-10-24
  • in Ruby, there's a better way. You can use the %q operator to apply single-quoting rules, but choose your own delimiter to mark the beginning and end of the string literal.


    puts %q!c:\napolean's documents\tomorrow's bus schedule.txt!
    puts %q/c:\napolean's documents\tomorrow's bus schedule.txt/
    puts %q^c:\napolean's documents\tomorrow's bus schedule.txt^
    puts %q(c:\napolean's documents\tomorrow's bus schedule.txt)
    puts %q{c:\napolean's documents\tomorrow's bus schedule.txt}
    puts %q<c:\napolean's documents\tomorrow's bus schedule.txt>
  • puts %Q!Say "Hello," #{name}.!
    puts %Q/What is "4 plus 5"? Answer: #{4+5}/

This link has been bookmarked by 1 people . It was first bookmarked on 24 Oct 2009, by Benx Shen.

  • 24 Oct 09
    • in Ruby, there's a better way. You can use the %q operator to apply single-quoting rules, but choose your own delimiter to mark the beginning and end of the string literal.


      puts %q!c:\napolean's documents\tomorrow's bus schedule.txt!
      puts %q/c:\napolean's documents\tomorrow's bus schedule.txt/
      puts %q^c:\napolean's documents\tomorrow's bus schedule.txt^
      puts %q(c:\napolean's documents\tomorrow's bus schedule.txt)
      puts %q{c:\napolean's documents\tomorrow's bus schedule.txt}
      puts %q<c:\napolean's documents\tomorrow's bus schedule.txt>
    • puts %Q!Say "Hello," #{name}.!
      puts %Q/What is "4 plus 5"? Answer: #{4+5}/