lib/lite/ruby/numeric.rb in lite-ruby-1.0.31 vs lib/lite/ruby/numeric.rb in lite-ruby-1.1.0

- old
+ new

@@ -13,27 +13,10 @@ def at_most(upper) self <= upper ? self : upper end - # rubocop:disable Metrics/MethodLength - def clamp(minimum, maximum = nil) - if minimum.is_a?(Range) - maximum = minimum.max - minimum = minimum.min - end - - if minimum > self - minimum - elsif maximum < self - maximum - else - self - end - end - # rubocop:enable Metrics/MethodLength - def close?(number, epsilon = 0.01) return self == number if epsilon.zero? a = to_f b = number.to_f @@ -77,12 +60,10 @@ def equal_to?(num) self == num end - alias eq? equal_to? - def fraction (self - truncate).abs end def fraction? @@ -91,18 +72,14 @@ def greater_than?(num) num < self end - alias gt? greater_than? - def greater_than_or_equal_to?(num) num <= self end - alias gteq? greater_than_or_equal_to? - def increment(amount = 1.0) self + amount end def inside?(start, finish) @@ -111,18 +88,14 @@ def less_than?(num) num > self end - alias lt? less_than? - def less_than_or_equal_to?(num) num >= self end - alias lteq? less_than_or_equal_to? - def markdown_percentage(percent) to_f * ((100.0 - percent.to_f) / 100.0) end def markup_percentage(percent) @@ -141,14 +114,10 @@ def not_equal_to?(num) self != num end - alias not_eq? not_equal_to? - alias inequal_to? not_equal_to? - alias ineq? not_equal_to? - def ordinal return 'th' if (11..13).cover?(abs % 100) case abs % 10 when 1 then 'st' @@ -204,12 +173,10 @@ def range(value) (self - value)..(self + value) end - alias plus_minus range - def root(num) self**(1.0 / num) end def round_down(num = 0) @@ -260,8 +227,18 @@ (alpha - beta).abs < epsilon else (alpha / beta - 1).abs < epsilon end end + + alias eq? equal_to? + alias gt? greater_than? + alias gteq? greater_than_or_equal_to? + alias inequal_to? not_equal_to? + alias ineq? not_equal_to? + alias lt? less_than? + alias lteq? less_than_or_equal_to? + alias not_eq? not_equal_to? + alias plus_minus range end end