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
# jukebox.rb | |
class Jukebox | |
attr_accessor :songs | |
def initialize(songs) | |
@songs = songs | |
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
# Construct an array with your favorite foods. It should have at least 5 elements. | |
fav_foods = ["penne pasta with garlic and oil", "yellow cherries", "milk shakes", "french fries", "bacon cheeseburgers"] | |
# Write a puts which returns your most favorite food out of the array. | |
fav_foods[4] | |
# Construct an array with the colors of the rainbow (ROYGBIV) |
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
# Chain at least 5 method calls to an object. Reduce this operation one chain at a time. | |
puts "rotator dad rotator".reverse.slice(8,3).capitalize.slice(0,0).concat("Father's Day is this weekend.") | |
# Don't just use the methods below, make up your own chain and try to see if you can do something fun with Ruby like in the example. | |
puts "rotator dad rotator".reverse | |
# #=> rotator dad rotator | |
puts "rotator dad rotator".reverse.slice(8,3) |
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
# Temperature bot is comfortable when it's room temperature (18-21C). Help him out by completing the method below: | |
def temperature_bot(temp) | |
case temp | |
when 18..21 | |
"I like this temperature" | |
else | |
"This is uncomfortable for me" | |
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
library { | |
:artist => { | |
"The Magnetic Fields" => { | |
"69 Love Songs" => ["Song 1", "Song 2"] | |
] | |
"Get Lost" => ["Song 1", "Song 2"] | |
} | |
"Netural Milk Hotel" => { | |
"In An Aeroplane Over the Sea" => ["Song 1", "Song 2"] | |
} |
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
$basketball_game = | |
{ | |
:team_1 => | |
{ | |
:team_name => "Knicks", | |
:colors => ["blue", "orange"], | |
:player_1 => | |
{ | |
:name => "Patrick Ewing", |
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
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" | |
codev2 = code.split('&') | |
codev3 = | |
codev2.collect do |x| | |
#split each string into two more strings | |
x.split('=') | |
end | |
codev4 = codev3.flatten #turns array x arrays into a single array. |
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 check_prime(number) | |
if number == 1 | |
"You'd think you were prime, but you're not." | |
elsif number == 2 | |
"We call 2 the Littlest Prime" | |
elsif number == 3 | |
"Octavian Prime" | |
elsif number == 4 | |
"Ain't Prime" | |
elsif number == 5 |
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 MyApp | |
def call(env) | |
[200, {'Content-Type' => 'text/html'}, ['<a style="background-color:red;">URGENT MSG</a> from Tiny Tim: Hello']] | |
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
require 'fis/test' | |
class Phone | |
def initialize(number) | |
@number = number.gsub(/\D/, '') | |
if @number.length == 11 && @number[0] == "1" | |
@number = @number[1..10] | |
end | |
end |