Method: Zold::Amount#initialize
- Defined in:
- lib/zold/amount.rb
#initialize(zents: nil, zld: nil) ⇒ Amount
Returns a new instance of Amount.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zold/amount.rb', line 39 def initialize(zents: nil, zld: nil) if !zents.nil? raise "Integer is required, while #{zents.class} provided: #{zents}" unless zents.is_a?(Integer) @zents = zents elsif !zld.nil? raise "Float is required, while #{zld.class} provided: #{zld}" unless zld.is_a?(Float) @zents = (zld * 2**FRACTION).to_i else raise 'You can\'t specify both coints and zld' end raise "The amount is too big: #{@zents}" if @zents > MAX raise "The amount is too small: #{@zents}" if @zents < -MAX end |