Sha256: ba7f925fea9644b3b1fdc43960dd43acb5352b515d39d062c7933b84e953ec95

Contents?: true

Size: 451 Bytes

Versions: 5

Compression:

Stored size: 451 Bytes

Contents

module BBLib

  # Used to keep any numeric number between a set of bounds. Passing nil as min or max represents no bounds in that direction.
  # min and max are inclusive to the allowed bounds.
  def self.keep_between num, min, max
    raise "Argument must be numeric: #{num} (#{num.class})" unless Numeric === num
    if !min.nil? && num < min then num = min end
    if !max.nil? && num > max then num = max end
    return num
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bblib-0.3.0 lib/number/bbnumber.rb
bblib-0.2.2 lib/number/bbnumber.rb
bblib-0.2.0 lib/number/bbnumber.rb
bblib-0.1.1 lib/math/bbmath.rb
bblib-0.1.0 lib/math/bbmath.rb