Created
March 16, 2012 19:55
-
-
Save mkoby/2052226 to your computer and use it in GitHub Desktop.
Intro to Ruby - 01 - Numbers and Strings
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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