Created
March 24, 2011 01:55
-
-
Save kibiz0r/884416 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
require 'ostruct' | |
class HockeyClient | |
def listen_for_hockey_scores | |
sleep 1 | |
yield score "Blues", "Cracknell" | |
sleep 0.1 | |
yield score "Red Wings", "Salei" | |
sleep 0.1 | |
yield score "Red Wings", "Helm" | |
sleep 1 | |
yield score "Red Wings", "Kronwall" | |
sleep 0.1 | |
yield score "Blues", "Backes" | |
sleep 0.2 | |
yield score "Blues", "D'Agostini" | |
sleep 0.2 | |
yield score "Red Wings", "Datsyuk" | |
sleep 0.1 | |
yield score "Red Wings", "Abdelkader" | |
end | |
private | |
def score(team, scorer) | |
OpenStruct.new :team => team, :scorer => scorer | |
end | |
end | |
if $0 == __FILE__ | |
hockey_client = HockeyClient.new | |
puts "Listening to the game..." | |
hockey_client.listen_for_hockey_scores do |goal| | |
puts "#{goal.scorer} scored a goal for #{goal.team}" | |
end | |
puts "The game is over." | |
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 './hockey_client' | |
class RedWingsFan | |
def initialize(hockey_client) | |
@hockey_client = hockey_client | |
end | |
def red_wings_goal_scorers | |
@hockey_client.enum_for(:listen_for_hockey_scores).select do |goal| | |
goal.team == "Red Wings" | |
end.map do |goal| | |
goal.scorer | |
end | |
end | |
end | |
red_wings_fan = RedWingsFan.new(HockeyClient.new) | |
puts "Red Wings scorers:" | |
red_wings_fan.red_wings_goal_scorers.each do |scorer| | |
puts scorer | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment