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 divide x, y | |
raise "Cannot divide by zero" if y == 0 | |
x / y | |
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
def divide x, y | |
if y == 0 | |
raise "Cannot divide by zero" | |
else | |
x / y | |
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
def previous | |
@trackIndex -= 1 | |
@trackIndex = 0 if @trackIndex < 0 | |
@play() | |
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
def title_case string | |
words = string.split " " | |
capitalized_words = words.map {|w| w.capitalize} | |
title = capitalized_words.join " " | |
return title | |
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
def calculate_total items | |
sum = 0 | |
for index in 0...items.length | |
sum += items[index].price | |
end | |
sum | |
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
def calculate_total items | |
items.map {|item| item.price}.reduce(&:+) | |
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
def comment_on_popularity | |
if !post.stars.empty? | |
if post.stars.count > 100 | |
"Congratulations. Your post is very popular." | |
elsif post.stars.count > 50 | |
"Well done. Your post is trending." | |
else | |
"Your post is doing well but could use a little attention." | |
end | |
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
def comment_on_popularity | |
if post.stars.empty? | |
"Your post is flying under the radar." | |
else | |
if post.stars.count > 100 | |
"Congratulations. Your post is popular!" | |
elsif post.stars.count > 50 | |
"Well done. Your post is trending." | |
else | |
"Doing well but could use a little attention." |
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 greet user | |
title = if user.admin? | |
"sir" | |
else | |
"you" | |
end | |
"Hello, #{title}!" | |
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
def greet user | |
"Hello, %s!" % if user.admin? | |
"sir" | |
else | |
"you" | |
end | |
end |
OlderNewer