Skip to content
Browse files

Organization and comments

  • Loading branch information...
1 parent 95e012f commit 4133741fa5554aeafae2ed92a42633d7248bf41c @nathanl committed
Showing with 13 additions and 8 deletions.
  1. +9 −8 person.rb
  2. +4 −0 secret_santa.rb
View
17 person.rb
@@ -1,14 +1,6 @@
class Person
attr_accessor :name, :group, :email, :santa
- def to_s
- "#{name} (#{group})"
- end
-
- def with_santa
- "#{self} - santa: #{santa}"
- end
-
def initialize(attrs)
self.name = attrs["name"]
self.group = attrs["group"]
@@ -22,4 +14,13 @@ def can_be_santa_of?(other)
def can_swap_santas_with?(other)
santa.can_be_santa_of?(other) && other.santa.can_be_santa_of?(self)
end
+
+ def to_s
+ "#{name} (#{group})"
+ end
+
+ def with_santa
+ "#{self} - santa: #{santa}"
+ end
+
end
View
4 secret_santa.rb
@@ -29,6 +29,10 @@
Logger.log person.with_santa
end
+# This is the nice part of Dennis's solution: if there are any invalid
+# assignments, they are corrected in a single pass. This is possible because
+# corrections are made in a way that ensures no new invalid assignments are
+# created.
Logger.log "Checking assignments for validity"
people.each do |person|
unless person.santa.can_be_santa_of?(person)

0 comments on commit 4133741

Please sign in to comment.
Something went wrong with that request. Please try again.