Sha256: 77daa91c424fe50f7e4adeae13cdac8e3cc54666d506b86337c844a5e1a3bef8

Contents?: true

Size: 579 Bytes

Versions: 1

Compression:

Stored size: 579 Bytes

Contents

module Mathy
  module Operations
    class Operation
      attr_reader :key

      def initialize(difficulty, key, verification)
        @difficulty = difficulty
        @key = key
        @verifier = verification
      end

      def play_turn
        operands = @difficulty.next_operands
        @verifier.check_answer("#{operands.join(" #{key} ")} = ", calculate(operands))
      end

      def matches?(other_key)
        key == other_key
      end

      def calculate(operands)
        operands.inject { |result, x| result.send(key.to_sym, x) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mathy-0.0.2 lib/mathy/operations/operation.rb