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
tabby_cat = "\tI'm tabbed in." | |
persian_cat = "I'm split\non a line." | |
backslash_cat = "I'm \\ a \\ cat." | |
fat_cat = <<MY_HEREDOC | |
I'll do a list: | |
\t* Cat food | |
\t* Fishies | |
\t* Catnip\n\t* Grass | |
MY_HEREDOC |
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
$ ruby ex10.rb | |
I'm tabbed in. | |
I'm split | |
on a line. | |
I'm \ a \ cat. | |
I'll do a list: | |
* Cat food | |
* Fishies | |
* Catnip | |
* Grass |
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
I'm tabbed in. | |
I'm split | |
on a line. | |
I'm \ a \ cat. | |
I'll do a list: | |
* Cat food | |
* Fishies | |
* Catnip | |
* Grass |
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
tabby_cat = "\tI'm tabbed in." | |
persian_cat = "I'm split\non a line." | |
backslash_cat = "I'm \\ a \\ cat." | |
fat_cat = <<MY_HEREDOC | |
I'll do a list: | |
\t* Cat food | |
\t* Fishies | |
\t* Catnip\n\t* Grass | |
MY_HEREDOC |
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
ex8.rb:5: syntax error, unexpected tIDENTIFIER, expecting ']' | |
puts formatter % [true, false, false, true] |
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 4 | |
one two three four | |
true false false true | |
%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s | |
I had this thing. That you could type up right. But it didn't sing. So I said goodnight. | |
$ |
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
formatter = "%s %s %s %s" | |
puts formatter % [1, 2, 3, 4] | |
puts formatter % ["one", "two", "three", "four]" | |
puts formatter % [true, false, false, true] | |
puts formatter % [ | |
"I had this thing.", | |
"That you could type up right.", | |
"But it didn't sing.", | |
"So I said goodnight." |
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
x = "There are #{10} types of people." | |
binary = "binary" | |
do_not = "don't" | |
y = "Those who know #{binary} and those who #{do_not}." | |
puts x | |
puts y | |
puts "I said: #{x}." | |
puts "I also said: '#{y}'." |
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
Macintosh:rubysamplecode toreystriffolino$ ruby ticket.rb | |
This ticket is for: ticket.rb:3:in `<main>': undefined method `event' for #<Object:0x007fece884b638> (NoMethodError) |
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
ticket = Object.new | |
print "This ticket is for: " | |
print ticket.event + ", at " | |
print ticket.venue + ", on " | |
puts ticket.date + " . " | |
print "The performer is " | |
puts ticket.performer + "." | |
print "the seat is " | |
print ticket.seat + ", " | |
print "and it costs $" |