Last active
August 29, 2015 14:16
-
-
Save phlipper/bc9cb7b5f5c0873f9fb4 to your computer and use it in GitHub Desktop.
TECH601-00 - Day 2 Example Code with output
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
a = [] | |
# look at "a" default value | |
puts a | |
# look at "a" converted to string | |
puts a.to_s | |
puts "#{a}" | |
# new list with things in it | |
b = [1, 2, 3] | |
# look at "b" default value | |
puts b | |
# look at "b" converted to string | |
puts b.to_s |
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 | |
2 | |
3 | |
[1, 2, 3] |
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
# assign some variables | |
a = 1 | |
b = 2 | |
c = a + b | |
# print output without newlines | |
print "The answer is: " | |
print c | |
print "\n" | |
# puts a | |
# puts b | |
# display the answer with newlines | |
puts "The answer is: " | |
puts c | |
# puts "\n" | |
# display the answer on one line, using `puts` and `+` - "concatenation" | |
puts "The answer is: " + c.to_s | |
# student example | |
print "The answer is: " | |
puts c | |
# solve using "interpolation" | |
puts "The answer is: #{c}" | |
# interpolation with evaluation | |
puts "The answer to #{a} + #{b} is: #{a + b}" | |
puts "The answer to #{a} + #{b} is: #{c}" | |
# concatenated version - looooooonghand :) | |
puts "The answer to " + a.to_s + " + " + b.to_s + " is: " + c.to_s | |
# "broken" interpolation | |
puts 'The answer to #{a} + #{b} is: #{c}' | |
# single/double quote fun! | |
puts 'This has "double quotes" in it' | |
puts "This has 'single quotes' in it" | |
puts "Interpolate #{"a string"} in here" | |
a_string = "a string" | |
puts "Interpolate #{a_string} in here" | |
# escape quotes | |
puts 'This has a \'single quoted string\' inside \n' | |
puts "This has a \"double quoted string\" inside \n" | |
# alternate string syntax - percent plus delimeter | |
puts %(This string has "double" and 'single' quotes \n) | |
puts %(This #{a_string} has "double" and 'single' quotes \n) | |
puts %|This string has "double" and 'single' quotes \n| | |
puts %[This string has "double" and 'single' quotes \n] | |
puts %.This string has "double" and 'single' quotes \n. |
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
The answer is: 3 | |
The answer is: | |
3 | |
The answer is: 3 | |
The answer is: 3 | |
The answer is: 3 | |
The answer to 1 + 2 is: 3 | |
The answer to 1 + 2 is: 3 | |
The answer to 1 + 2 is: 3 | |
The answer to #{a} + #{b} is: #{c} | |
This has "double quotes" in it | |
This has 'single quotes' in it | |
Interpolate a string in here | |
Interpolate a string in here | |
This has a 'single quoted string' inside \n | |
This has a "double quoted string" inside | |
This string has "double" and 'single' quotes | |
This a string has "double" and 'single' quotes | |
This string has "double" and 'single' quotes | |
This string has "double" and 'single' quotes | |
This string has "double" and 'single' quotes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment