Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/chance/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#percentObject



14
15
16
# File 'lib/chance/core_extensions.rb', line 14

def percent
  Percentage.new(self)
end

#reduce_by(percentage = 50.percent, &block) ⇒ Object Also known as: reduce



18
19
20
21
22
23
24
25
26
# File 'lib/chance/core_extensions.rb', line 18

def reduce_by(percentage = 50.percent, &block)
  block ||= Proc.new {|number| number.small?}
  return self if block.call(self)
  reduced_to = self
  until block.call(reduced_to)
    reduced_to = reduced_to.reduce_to(percentage)
  end
  Integer(reduced_to)
end