Skip to content

Instantly share code, notes, and snippets.

puts "The (L) Train, The (N) Train, The (S)ix Train"
puts "Choose a train line by letter."
selection = gets.chomp.to_s
if selection == "L"
puts "You selected the L train."
elsif selection == "N"
puts "You selected the N train."
elsif selection == "S"
puts "You selected the Six Train."
puts "The (L) Train, The (N) Train, The (S)ix Train"
puts "Choose a train line by letter."
selection = gets.chomp.to_s
if selection == "L"
puts "You selected the L train."
puts "8th Ave, 6th Ave, Union Square, 3rd Ave, 1st Ave, Bedford Ave"
elsif selection == "N"
puts "You selected the N train."
puts "Times Square, Herald Square, 28th St, 23rd St - HMH Nexus,
loop do
puts "The (L) Train, The (N) Train, The (S)ix Train"
puts "Do you wish to quit?"
continue = gets.chomp
if continue == "Yes"
puts "Thank You"
break
else
puts "Choose a train line by letter."
end
loop do
puts "List train lines (T)? List Stations (Sta)? Quit program (Q)? Please make a selection."
answer = gets.chomp.to_s
if answer == "T"
puts "The (L) Train, The (N) Train, The (S)ix Train"
elsif answer == "Sta"
puts "The (L) Train, The (N) Train, The (S)ix Train Choose a train line by letter."
def main_menu
puts "List train lines (T)? List Stations (Sta)? Quit program (Q)? Please make a selection."
end
loop do
main_menu
answer = gets.chomp.to_s
if answer == "T"
What were some of the issues with your first iteration of HMH Rail?
- It took way longer than it should have, considering its length. I got completely lost somewhere between steps 3 and 4.
Is there a lot of repeated code?
- Yes, for each if/eslif/else I repeated the same three lines of code. I also repeated the “You selected the __ train” string three times, which could possibly be replaced with a method that contains something along the lines of ‘puts “You selected the #{ } train.”’ I also repeated the string stating the stations options twice.
How flexible is the code?
- The code was not flexible at all. There was no way to add extra train lines and corresponding stations.
Where do you see room for improvement?
- All over the place to be honest.
What are the nouns for this problem domain? What real-world objects are we trying to represent through our code?
- Train lines, train stations.
trains = {
"L Train" => "8th Ave, 6th Ave, Union Square, 3rd Ave, 1st Ave, Bedford Ave",
"N Train" => "Times Square, Herald Square, 28th St, 23rd St - HMH Nexus, Union Square, 8th Ave",
"6 Train" => "Grand Central, 33rd St, 28th St, 23rd St, Union Square, Astor Place"
}
loop do
puts "To view all train lines, type lines."
puts "To view all stations for line, type stations."
@msmith7904
msmith7904 / gist:5b91bb7ea5a3d3fa6989
Created October 26, 2014 15:59
Problematic Word Class Construction
class Word
def initialize(word)
@letters = word.split('').map do |letter|
{
:letter => letter,
:hidden => true
}
end
end
<!-- same as above -->
<router-link :to="{ path: 'foo' }">Foo</router-link>
<!-- named route -->
<router-link :to="{ name: 'foo', params: { foo: 'bar' }}">Foo</router-link>