Commit 816f53a

mo khan <mo.khan@gmail.com>
2020-08-25 20:51:23
Allow for variable # of cards to match
1 parent 61783db
Changed files (1)
misc
cards
misc/cards/main.rb
@@ -12,17 +12,15 @@ class Card
     @number = raw[1..-1].size
   end
 
-  def match?(y, z)
-    prefix_count = [self.prefix, y.prefix, z.prefix].uniq.count
-    if prefix_count == 1 || prefix_count == 3
-      letter_count = [self.letter, y.letter, z.letter].uniq.count
-      if letter_count == 1 || letter_count == 3
-        number_count = [self.number, y.number, z.number].uniq.count
-        return true if number_count == 1 || number_count == 3
-      end
+  def match?(*others)
+    others << self
+
+    [:prefix, :letter, :number].each do |property|
+      count = others.map(&property).uniq.count
+      return false if count != 1 && count != others.size
     end
 
-    false
+    true
   end
 
   def to_s