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 test(title, &b) | |
begin | |
if b | |
result = b.call | |
if result.is_a?(Array) | |
puts "fail: #{title}" | |
puts " expected #{result.first} to equal #{result.last}" | |
elsif result | |
puts "pass: #{title}" | |
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
puts "What do you want me to do? (Remember to type 'help' if you need it!)" | |
prompt = '> ' | |
print prompt | |
input = gets.chomp.downcase.strip | |
puts "Sure... no problem" | |
# songs = [ | |
# "The Magnetic Fields - 69 Love Songs - Parades Go By", | |
# "The Magnetic Fields - Get Lost - Smoke and Mirrors", | |
# "The Magnetic Fields - Get Lost - You, Me, and the Moon", |
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
# Assignment | |
# write a true expression using == | |
a == a | |
# write a false expression using == | |
a == b | |
# write a true expression using != | |
true != false | |
# write a false expression using != |
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
# Define the fizzbuzz method to do the following: 10pts | |
# Use the modulo % method (divisible by) | |
# 2 % 2 #=> true | |
# 1 % 2 #=> false | |
# If a number is divisible by 3, puts "Fizz". | |
# If a number is divisible by 5, puts "Buzz". | |
# If a number is divisible by 3 and 5, puts "FizzBuzz" | |
# Use if statements 2pts |
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
# Write a program that tells you the following: | |
# | |
# Hours in a year. How many hours are in a year? - 6pts | |
# Minutes in a decade. How many minutes are in a decade? - 6pts | |
# Your age in seconds. How many seconds old are you? - 6pts | |
# | |
# Define at least the following methods to accomplish these tasks: | |
# | |
# seconds_in_minutes(1) #=> 60 - 3pts | |
# minutes_in_hours(1) #=> 60 - 3pts |
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 Artist | |
def genres | |
@songs.collect{|s| s.genre} | |
end | |
end | |
class Song | |
attr_accessor :name, :song, :artist, :genre | |
def genre=(genre) |
NewerOlder