Sha256: 77668d96c3a86fd29fde7962db6df7c3fd2ee46e8cde6e5ca1c9c74d8449a175
Contents?: true
Size: 732 Bytes
Versions: 1
Compression:
Stored size: 732 Bytes
Contents
# frozen_string_literal: true module SimpleMath # Calculator class Calculator attr_accessor :start def self.run(start: 0, &block) new(start: start).send(:calculate, &block) end private def initialize(start:) @start = start end def calculate operations_hash = operations(start) yield operations_hash if block_given? operations_hash[:total].call end def operations(total) { total: -> { total }, '+': ->(number) { total += number.to_f }.curry, '-': ->(number) { total -= number.to_f }.curry, '*': ->(number) { total *= number.to_f }.curry, '/': ->(number) { total /= number.to_f }.curry } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simple_math-0.1.1 | lib/simple_math/calculator.rb |