Skip to content

Instantly share code, notes, and snippets.

@elizabrock
Created July 7, 2014 16:43
Show Gist options
  • Save elizabrock/c12b44c347211ed7f480 to your computer and use it in GitHub Desktop.
Save elizabrock/c12b44c347211ed7f480 to your computer and use it in GitHub Desktop.
Cheers Exercise - Cohort Blueberry
# Build on the results of our in-class exploration to output, for example:
# Give me an... A
# Give me a... B
# Give me a... B
# Give me a... Y
# ABBY’s just GRAND!
# When given the input of “Abby”.
# Note: the “a” vs. “an”
# P.S.: name.methods - Object.methods
puts "What's your name?"
name = gets.chomp
if name.empty?
puts "You must enter your name!"
exit
end
puts "Your name is #{name}"
name.each_char do |char|
puts "Give me... #{char}"
end
elizabrock@rMBP:~$ irb
2.1.1 :001 > 2 + 2
=> 4
2.1.1 :002 > "foo"
=> "foo"
2.1.1 :003 > puts "foo"
foo
=> nil
2.1.1 :004 > puts("foo")
foo
=> nil
2.1.1 :005 > arr = ["Bluebeard", "Blackbeard", "Jack"]
=> ["Bluebeard", "Blackbeard", "Jack"]
2.1.1 :006 > arr
=> ["Bluebeard", "Blackbeard", "Jack"]
2.1.1 :007 > arr.each do |pirate|
2.1.1 :008 > puts pirate + "was a pirate!"
2.1.1 :009?> end
Bluebeardwas a pirate!
Blackbeardwas a pirate!
Jackwas a pirate!
=> ["Bluebeard", "Blackbeard", "Jack"]
2.1.1 :010 > arr.each do |pirate|
2.1.1 :011 > puts pirate + " was a pirate!"
2.1.1 :012?> end
Bluebeard was a pirate!
Blackbeard was a pirate!
Jack was a pirate!
=> ["Bluebeard", "Blackbeard", "Jack"]
2.1.1 :013 > arr.each do |pirate|
2.1.1 :014 > puts "#{pirate} was a pirate!"
2.1.1 :015?> end
Bluebeard was a pirate!
Blackbeard was a pirate!
Jack was a pirate!
=> ["Bluebeard", "Blackbeard", "Jack"]
2.1.1 :016 > arr.each{ |pirate| puts "#{pirate} was a pirate" }
Bluebeard was a pirate
Blackbeard was a pirate
Jack was a pirate
=> ["Bluebeard", "Blackbeard", "Jack"]
2.1.1 :017 > arr.map{|pirate| pirate.upcase }
=> ["BLUEBEARD", "BLACKBEARD", "JACK"]
2.1.1 :018 > arr
=> ["Bluebeard", "Blackbeard", "Jack"]
2.1.1 :019 > exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment