Skip to content

Instantly share code, notes, and snippets.

@kironroy kironroy/CmhF-0.rb
Created Aug 13, 2016

Embed
What would you like to do?
https://repl.it/CmhF/0 created by kironroy
# 1992 Dream Team at Olympic Games in Barcelona, Spain
team = {
Karl_Malone: "Power Forward",
Christian_Laettner: "Power Forward",
Charles_Barkley: "Power Forward",
David_Robinson: "Center",
Patrick_Ewing: "Center",
Scottie_Pippen: "Strong Forward",
Chris_Mullen: "Strong Forward",
Larry_Bird: "Strong Forward",
Michael_Jordan: "Strong Guard",
Clyde_Drexler: "Strong Guard",
John_Stockton: "Point Guard",
Magic_Johnson: "Point Guard"
}
# Power Forwards
power_f_lam= lambda { |player, position| position == "Power Forward"}
pf = team.select(&power_f_lam)
# Strong Forwards
strong_f_lam = lambda { |player, position| position == "Strong Forward"}
sf = team.select(&strong_f_lam)
# Centers
center_lam = lambda { |player, position| position == "Center"}
c = team.select(&center_lam)
# Strong Guards
s_guards_lam = lambda { |player, position| position == "Strong Guard"}
sg = team.select(&s_guards_lam)
# Point Guards
p_guards_lam = lambda { |player, position| position == "Point Guard"}
pg = team.select(&p_guards_lam)
p ' Welcome to the Dream team Hash '
p '--' * 20
p ' What would you like to do? '
p '--' * 20
p ' Type pf to display the Power Forwards. '
p '--' * 20
p ' Type sf to display the Strong Forwards. '
p '--' * 20
p ' Type c to display the Centers '
p '--' * 20
p ' Type sg to display the Strong Guards. '
p '--' * 20
p ' Type pg to display the Point Guards. '
p '--' * 20
p ' Type team to display the whole team. '
choice = gets.chomp.downcase
case choice
when 'pf'
p pf
when 'sf'
p sf
when 'c'
p c
when 'sg'
p sg
when 'pg'
p pg
when 'team'
p team
else p " please type: pf, sf, c, sg, or pg "
choice = gets.chomp.downcase
p " please type: pf, sf, c, sg, or pg "
choice = gets.chomp.downcase
p " please type: pf, sf, c, sg, or pg "
choice = gets.chomp.downcase
p "fail"
end
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
>>> " Welcome to the Dream team Hash "
"----------------------------------------"
" What would you like to do? "
"----------------------------------------"
" Type pf to display the Power Forwards. "
"----------------------------------------"
" Type sf to display the Strong Forwards. "
"----------------------------------------"
" Type c to display the Centers "
"----------------------------------------"
" Type sg to display the Strong Guards. "
"----------------------------------------"
" Type pg to display the Point Guards. "
"----------------------------------------"
" Type team to display the whole team. "
sg
{:Michael_Jordan=>"Strong Guard", :Clyde_Drexler=>"Strong Guard"}
=> {:Michael_Jordan=>"Strong Guard", :Clyde_Drexler=>"Strong Guard"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.