This file contains 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
toppings = %w(pepperoni mushroom bacon pineapple) | |
def pizza(toppings) | |
pizza.map do |topping| | |
puts "I love #{topping} pizza!" | |
end | |
end |
This file contains 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 love pepperoni pizza!", | |
"I love mushroom pizza!", | |
"I love bacon pizza!", | |
"I love pineapple pizza!" | |
] |
This file contains 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 pizza(toppings) | |
my_statements = [] | |
toppings.each do |topping| | |
my_statements << "I love #{topping} pizza!" | |
end | |
my_statements | |
end |
This file contains 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
["pepperoni", "mushroom", "bacon", "pineapple"] |
This file contains 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 love pepperoni pizza! | |
I love mushroom pizza! | |
I love bacon pizza! | |
I love pineapple pizza! |
This file contains 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
toppings = %w(pepperoni mushroom bacon pineapple) | |
def pizza(toppings) | |
toppings.each do |topping| | |
puts "I love #{topping} pizza!" | |
end | |
end |
This file contains 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
var costume: String? = "Werewolf" | |
println(costume) // Optional("Werewolf") | |
costume = costume! + " dressed as Michael J Fox" | |
println(costume) // Optional("Werewolf dressed as Michael J Fox") |
This file contains 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
var costume: String? = "Werewolf" | |
println(costume) // Optional("Werewolf") | |
costume = costume + " dressed as Michael J Fox" // Compiler Error | |
if let something = costume { | |
// The value is not nil, use it with confidence | |
something = something + " dressed as Michael J Fox" | |
println(something) // "Werewolf dressed as Michael J Fox" | |
} else { |
This file contains 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
NSString *costume = @"Dracula"; | |
// ... | |
if (costume == nil) { | |
// Do something for this plain clothes guest | |
} else { | |
// Do something else for this costumed guest | |
} |
This file contains 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
// Non-optional vars | |
var mutableBeverage = "Leffe" | |
println(mutableBeverage) // "Leffe" | |
mutableBeverage = "Bud" | |
println(mutableBeverage) // "Bud" | |
mutableBeverage = mutableBeverage + "weiser" | |
println(mutableBeverage) // "Budweiser" |