Created
April 25, 2016 19:35
-
-
Save tjr05d/f6527e8510f9fe8c6bf43a332e009378 to your computer and use it in GitHub Desktop.
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
# create a 2d array | |
# with a hash at each position | |
# that has the following keys: | |
# - name | |
# - age | |
# - sex | |
# then create a Sinatra route that looks | |
# for the x & y query string params | |
# then uses them to return information about the student | |
# in that seat | |
require 'sinatra' | |
classroom = [ | |
[{ | |
name: "Paul", | |
sex: "Male" | |
}, { | |
name: "Bryan with a y", | |
age: "24", | |
sex: "Male" | |
}, { | |
name: "Jasmine", | |
age: "23", | |
sex: "Female" | |
}, { | |
name: "Brian with an i", | |
age: "33", | |
sex: "Male" | |
}, { | |
name: "David", | |
age: "42", | |
sex: "Male" | |
}], [ { | |
name: "Tim", | |
age: "31", | |
sex: "Male" | |
}, { | |
name: "Don", | |
age: "49", | |
sex: "Male" | |
}, { | |
name: "Serena", | |
age: "31", | |
sex: "Female" | |
}, { | |
name: "Juan", | |
age: "39", | |
sex: "Not tonight" | |
}, { | |
name: "Deri", | |
age: "40", | |
sex: "Female" | |
}, { | |
name: "Deanna", | |
age: "24", | |
sex: "Female" | |
}], [{ | |
name: "Jaime", | |
age: "33", | |
sex: "Male" | |
}, { | |
name: "Kevin", | |
age: "32", | |
:sex => "Male" | |
}, { | |
name: "Deven", | |
age: "31", | |
:sex => "Male" | |
}, { | |
name: "Greg", | |
age: "30", | |
home: "Ft. Lauderdale" | |
}, { | |
name: "Daniel", | |
age: "19", | |
:sex => "Male" | |
}] | |
] | |
get '/' do | |
row = params['x'].to_i | |
seat = params['y'].to_i | |
begin | |
student = classroom[row][seat] | |
rescue NoMethodError | |
return "No student!" | |
end | |
student.map do |k, v| | |
"#{k}: #{v}<br/>" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment