Skip to content

Instantly share code, notes, and snippets.

@mkoby
Created March 16, 2012 19:55
Show Gist options
  • Select an option

  • Save mkoby/2052226 to your computer and use it in GitHub Desktop.

Select an option

Save mkoby/2052226 to your computer and use it in GitHub Desktop.
Intro to Ruby - 01 - Numbers and Strings
1 + 1 # => 2
x = 2
x * 2 # => 4
x *= 2# => 4
x = x * 2 # => 8
pi = 3.14
pi * (5 * 5) # => 78.5
2 + 3 # => 5
2 * 3 # => 6
3 - 2 # => 1
6 / 3 # => 2
s = "Hello, World!" # => "Hello, World"
a = "Hello,"
b = " World!"
a + b # => "Hello, World!"
a + " World" # => "Hello, World!"
"#{a}#{b}" # => "Hello, World"
## String Interpolation
x = 2
y = 6
new_string = "#{x} + #{y} = #{x + y}" # => "2 + 6 = 8"
## String Methods
s = "This is my string variable"
s.length # => 26
s.upcase # => "THIS IS MY STRING VARIABLE"
s.downcase # => "this is my string variable"
s.sub("string", "text") # => "This is my text variable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment