Last active
January 13, 2018 09:51
-
-
Save pointcom/f2ea137ac048e23c8eb742453e64c20f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = "Stuart" | |
# To build a string and escape double quote at the same time | |
%q(Hello, my name is "#{name}") | |
=> "Hello, my name is \"\#{name}\"" | |
# The same exist for single quote | |
%Q(Hello, my name is "#{name}") | |
=> "Hello, my name is \"Stuart\"" | |
# To build an array of strings without interpolation | |
%w(bobby brown #{name}) | |
=> ["bobby", "brown", "\#{name}"] | |
# To build an array of strings with interpolation | |
%W(bobby brown #{name}) | |
=> ["bobby", "brown", "Stuart"] | |
# Create an array of symbols without interpolation | |
%i(hello world #{name}) | |
=> [:hello, :world, :"\#{name}"] | |
# Create an array of symbols with interpolation | |
%I(hello world #{name}) | |
=> [:hello, :world, :Stuart] | |
# Execute a system command | |
%x(ls) | |
=> "bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar\n" | |
# Create a symbol | |
%s(hello world) | |
=> :"hello world" | |
# Create a Regular Expression | |
%r(^hel\D+d$) | |
=> /^hel\D+d$/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment