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 hello | |
"Hello!" | |
end | |
def greet(name) | |
"Hello, #{name}!" | |
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 ftoc (fahrenheit) | |
(fahrenheit - 32) * 5/9.to_f | |
end | |
def ctof (celsius) | |
celsius * 9/5.to_f + 32 | |
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 add (num1, num2) | |
num1 + num2 | |
end | |
def subtract (num1, num2) | |
num1 - num2 | |
end | |
def sum (array) | |
answer = 0 |
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 echo (word) | |
word | |
end | |
def shout (word) | |
word.upcase | |
end | |
def repeat (word, times = 2) | |
(word * times).gsub(word, " #{word}").strip |
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 translate (phrase) | |
vowels = %w{a e i o u} | |
words = phrase.split(' ') | |
first_letter_of_phrase = phrase.scan(/./).first | |
new_phrase = [] | |
words.each do |word| | |
word = word.downcase | |
first_letter = word.scan(/./).first |
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 reverser &proc | |
answer = [] | |
proc.call.split(' ').each do |word| | |
answer<<word.reverse | |
end | |
answer.join(' ') | |
end | |
def adder number=1, &proc | |
number + proc.call |
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 measure number=1, &someproc | |
start_time = Time.now | |
number.times {someproc.call} | |
run_time = (Time.now - start_time) / number | |
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
class Friend | |
def greeting(person = nil) | |
person.nil? ? "Hello!" : "Hello, #{person}!" | |
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
class Temperature | |
def initialize (input) | |
@temperature = input | |
end | |
def ftoc (number) | |
number * 9/5.to_f + 32 | |
end | |
def ctof (number) |
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
class Book | |
attr_accessor :title | |
def title= (title) | |
do_not_capitalize = %w{the and a an in of} | |
answer = [] | |
title.split(' ').each do |word| | |
do_not_capitalize.include?(word) ? word = word.downcase : word = word.capitalize | |
word == "i" ? word = word.capitalize : word | |
answer << word |
OlderNewer