Skip to content

Instantly share code, notes, and snippets.

@erickuhn19
Created May 6, 2015 01:44
Show Gist options
  • Save erickuhn19/73c87ef00e22c9cdd42a to your computer and use it in GitHub Desktop.
Save erickuhn19/73c87ef00e22c9cdd42a to your computer and use it in GitHub Desktop.
DHH score challenge
class Event
attr_accessor :name
attr_accessor :score
def initialize(name, score=0)
@name = name
@score = score
end
end
require_relative 'event'
require_relative 'game'
event1 = Event.new("IssueEvent", 7)
event2 = Event.new("IssueCommentEvent", 6)
event3 = Event.new("PushEvent", 5)
event4 = Event.new("PullRequestReviewCommentEvent", 4)
event5 = Event.new("WatchEvent", 3)
event6 = Event.new("CreateEvent", 2)
event7 = Event.new("AnyOtherEvent", 1)
new_game = Game.new("NewGame")
new_game.add_events_to_hash(event1)
new_game.add_events_to_hash(event2)
new_game.add_events_to_hash(event3)
new_game.add_events_to_hash(event4)
new_game.add_events_to_hash(event5)
new_game.add_events_to_hash(event6)
new_game.add_events_to_hash(event7)
puts new_game.total_points
require_relative 'event'
class Game
attr_accessor :title
attr_accessor :all_events
def initialize(title)
@title = title
@all_events = Hash.new(0)
end
def add_events_to_hash(event)
@all_events[event.name] += event.score
end
def total_points
@all_events.values.reduce(0, :+)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment