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
print "What is your name? " | |
name = gets.chomp | |
puts "Alright #{name} what would you like to buy today? | |
We currently have a beach ball, a tennis ball and a giraffe. | |
The beach ball is 12.99, the tennis ball is 4.99 and the | |
giraffe is 93.86. You currently have $120. " | |
purchase = gets.chomp | |
if purchase == "tennis ball" | |
price = 4.99 |
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
prices = { | |
"tennis ball" => 4.99, | |
"beach ball" => 12.99, | |
"giraffe" => 93.86, | |
} | |
print "What is your name? " | |
name = gets.chomp |
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
Copying data from test1.txt,test2.txt to . | |
ex17.rb:5:in `initialize': No such file or directory @ rb_sysopen - test1.txt,test2.txt (Errno::ENOENT) | |
from ex17.rb:5:in `open' | |
from ex17.rb:5:in `<main>' |
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
# this one is just like your scripts with ARGV | |
def print_two(*args) | |
arg1, arg2 = args | |
puts "arg1: #{arg1}, arg2: #{arg2}" | |
end | |
# That *args is actually pointless, we can just do this: | |
def print_two_again(arg1, arg2) | |
puts "arg1: #{arg1}, arg2: #{arg2}" | |
end |
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
# Just 1 argument | |
def print_one(arg1) | |
puts "arg1: #{arg1}" | |
end |
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
words = Ex25.break_words(sentence) | |
SystemStackError: stack level too deep |
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
def Ex25.sort_words(words) | |
return words.sort | |
end |
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
module Ex25 | |
# This function will break up words for us. | |
def Ex25.break_words(stuff) | |
words = stuff.split(' ') | |
return words | |
end | |
# Sorts the words. | |
def Ex25.sort_words(words) |
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
module Ex26 | |
# This function will break up words for us. | |
def Ex26.break_words(stuff) | |
words = stuff.split(' ') | |
return words | |
end | |
# Sorts the words. | |
def Ex26.sortwords(words) |
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
# This function will break up words for us. | |
def break_words(stuff) | |
words = stuff.split(' ') | |
return words | |
end | |
# Sorts the words. | |
def sort_words(words) | |
return words.sort | |
end |