Skip to content

Instantly share code, notes, and snippets.

# Testing / Assertion
# Define a method that takes two values and compares them, printing pass or fail
def assert_equal(actual, expected)
if actual == expected
return true
else
return false
end
class Jukebox
attr_accessor :songs
def welcome
puts "Welcome to jukebox."
end
def instruction
puts "What would you like to do? Please enter list, play, help, or exit"
instruction = gets.downcase.chomp
@surrealdetective
surrealdetective / pokemon-fis002-alex-au
Created June 15, 2013 22:22
remaking the methods for all, any, and none, i choose you!
def myAll(myTeam)
if block_given?
myTeam.each do |pokemon|
if !yield pokemon
return false
end
end
end
return true
end
#solution 1
def prime1?(number)
2.upto(number-1) do |composite|
return "#{number} is not prime" if number%composite == 0
end
return "#{number} is prime"
end
#solution 2
@surrealdetective
surrealdetective / decoder-fis002-alex-au
Created June 14, 2013 03:47
decode the tree felled
code = "fx1=ZY&iX3=ZW&hm5=ZU&dg7=ZS&ei9=ZQ&ge11=ZO&tr13=ZM&hh15=ZK&uX17=ZI&si19=ZG&tX21=ZE&Xn23=ZC&hp25=ZA&pX27=YY&dl29=YW&wo31=YU&XX33=YS&XX35=YQ&re37=YO&et39=YM&ia41=YK&wn43=YI&uo45=YG&dX47=YE&so49=YC&ec51=YA&do53=XY&sX55=XW&xr57=XU&so59=XS&aX61=XQ&ph63=XO&ni65=XM&nX67=XK&Xa69=XI&yX71=XG&aX73=XE&ei75=XC&ie0=ZZ&Xa2=ZX&Xy4=ZV&aX6=ZT&Xn8=ZR&in10=ZP&hp12=ZN&Xa14=ZL&os16=ZJ&rx18=ZH&Xs20=ZF&od22=ZD&ce24=ZB&os26=YZ&Xd28=YX&ou30=YV&nw32=YT&ai34=YR&te36=YP&er38=YN&XX40=YL&XX42=YJ&ow44=YH&ld46=YF&Xp48=YD&ph50=YB&nX52=XZ&Xt54=XX&is56=XV&Xu58=XT&hh60=XR&rt62=XP&eg64=XN&ie66=XL&gd68=XJ&mh70=XH&Xi72=XF&xf74=XD"
chars = ('A'..'ZZ').to_a.reverse
#tactic:
#isolate the key-value pair, which is
#ultimately, you combine hashes using the = Hash [key1, value1, key2, value2, key3, value3]
def code_to_hash (code)
code_split_again = []
#create hash from array (a method)
#parameters: an array of nested hashes
#input
items = [ {"AVOCADO" => {:price => 3.00, :clearance => true}},
{"KALE" => {:price => 3.00,:clearance => false}},
{"BLACK_BEANS" => {:price => 2.50,:clearance => false}},
{"ALMONDS" => {:price => 9.00, :clearance => false}},
{"TEMPEH" => {:price => 3.00,:clearance => true}},
@surrealdetective
surrealdetective / temperature-bot-fis-alex-au
Created June 11, 2013 04:20
temperature_bot likes feelings
def temperature_bot(temp)
case temp
when 18..21
"I like this temperature"
else
"This is uncomfortable for me"
end
end
@surrealdetective
surrealdetective / method-chain-fis-alex-au
Created June 11, 2013 04:07
method chaining to the meaning of life
puts "what is the meaning of life?".slice(12, 7)
# => meaning
puts "what is the meaning of life?".slice(12, 7).concat(" can the universe really provide? ")
# => meaning can the universe really provide?
puts "what is the meaning of life?".slice(12, 7).concat(" can the universe really provide? ").reverse
# => ?edivorp yllaer esrevinu eht nac gninaem
puts "what is the meaning of life?".slice(12, 7).concat(" can the universe really provide? ").reverse.strip
# Create Hashes for the following use-cases.
# A movie collection that organizes by genres
movie_genre = {
:anime => ['The Girl Who Leapt Through Time', "Akira"],
:comedy => ['Bernie', 'Zoolander'],
:action => ['The Matrix']
}
# Construct an array with your favorite foods. It should have at least 5 elements.
# Write a puts which returns your most favorite food out of the array.
fav_foods = ['lasagna', 'salmon', 'avocado', 'grapefruit', 'milkshake']
puts fav_foods[1]
# Construct an array with the colors of the rainbow (ROYGBIV)
# Slice the colors Red, Orange, and Yellow out of the array.
colors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet']