Percent Literals (MOTM 2010.09)
Upcoming SlideShare
Loading in...5
×
 

Percent Literals (MOTM 2010.09)

on

  • 1,021 views

Ruby Method of the Month 2010.09. Lightning talk for the Columbus Ruby Brigade.

Ruby Method of the Month 2010.09. Lightning talk for the Columbus Ruby Brigade.

Statistics

Views

Total Views
1,021
Views on SlideShare
1,021
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Percent Literals (MOTM 2010.09) Percent Literals (MOTM 2010.09) Presentation Transcript

  • % PERCENT LITERALS RUBY METHOD (SORT OF) OF THE MONTH KEVIN MUNC @MUNCMAN
  • WHAT DOES THIS DO? %%COLUMBUS RUBY BRIGADE%
  • WHAT DOES THIS DO? %%COLUMBUS RUBY BRIGADE% "COLUMBUS RUBY BRIGADE"
  • %Q AND %q ‘Q’ is for Quotes No escaping quotation marks in your strings! Uppercase Q acts like double-quotes. You get String interpolation. You can leave off ‘Q’, but it’s not recommended. Lowercase Q acts like single-quotes.
  • %Q AND %q Put a delimiter after the ‘Q’ and at the end. Choose any delimiter you want. Even semicolon (;), quotes (“ or ‘) or percent (%) itself. Letters can be problematic as delimiters. Just don’t use a character that is in the delimited value.
  • % Instead of: "This is "Spinal Tap"" You can do this: %q{This is "Spinal Tap"}
  • % Instead of: "This is "Spinal Tap"" You can do this: %q{This is "Spinal Tap"} Or instead of this: what = "Glove" "Smell the "#{what}"" You can do this: %Q{Smell the "#{what}"}
  • % Instead of: "This is "Spinal Tap"" You can do this: %q{This is "Spinal Tap"} Or instead of this: what = "Glove" "Smell the "#{what}"" You can do this: %Q{Smell the "#{what}"} Or instead of this: ""None" "more" "black"" You can do this: %q<"None" "more" "black">
  • %W AND %w ‘W’ is for Words (or Whitespace). Let you create an array of strings: Without needing quotes. Without needing commas.
  • %W AND %w Uppercase W allows for string interpolation. Lowercase W does not. You cannot use quotes to group together a phrase containing whitespace. Instead, escape the whitespace.
  • % %w!Break Like the Wind!
  • % %w!Break Like the Wind! ["Break", "Like", "the", "Wind"]
  • % %w!Break Like the Wind! ["Break", "Like", "the", "Wind"] %W|Hello Cleveland! #{what}|
  • % %w!Break Like the Wind! ["Break", "Like", "the", "Wind"] %W|Hello Cleveland! #{what}| ["Hello", "Cleveland!", "Glove"]
  • % %w[Shark Sandwich "Big Bottom"]
  • % %w[Shark Sandwich "Big Bottom"] ["Shark", "Sandwich", ""Big", "Bottom""]
  • % %w[Shark Sandwich "Big Bottom"] ["Shark", "Sandwich", ""Big", "Bottom""] %w[Shark Sandwich Big Bottom]
  • % %w[Shark Sandwich "Big Bottom"] ["Shark", "Sandwich", ""Big", "Bottom""] %w[Shark Sandwich Big Bottom] ["Shark", "Sandwich", "Big Bottom"]
  • %
  • %x ‘X’ is for eXecute. Let’s you specify a system command without the backtick, backquote or grave accent marks (`). But you can use backticks as delimiters if you’d like - if they aren’t in the command... There is no uppercase version. String interpolation is supported.
  • % %x(date)
  • % %x(date) "Mon Sep 20 01:10:55 EDT 2010n"
  • % %x(date) "Mon Sep 20 01:10:55 EDT 2010n" %x$pwd$
  • % %x(date) "Mon Sep 20 01:10:55 EDT 2010n" %x$pwd$ "/Users/muncmann"
  • %r ‘R’ is for Regular Expression. Let’s you specify a regex without having to escape forward slashes (/). But you can use slashes as delimiters if you’d like - if they aren’t in the regex... There is no uppercase version. String interpolation is supported.
  • Instead of: % You can do this: //usr/local/bin/ %r{/usr/local/}
  • %s ‘S’ is for Symbol. This seems to be the least known percent literal of the bunch. There is no uppercase version. String interpolation is not supported.
  • % %s{stonehenge}
  • % %s{stonehenge} :stonehenge
  • % %s{stonehenge} :stonehenge %s{Tonight I'm Gonna Rock You Tonight}
  • % %s{stonehenge} :stonehenge %s{Tonight I'm Gonna Rock You Tonight} :"Tonight I'm Gonna Rock You Tonight"
  • QUESTIONS?