Class: String

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

Instance Method Summary collapse

Instance Method Details

#oddsObject



31
32
33
34
35
# File 'lib/chance/core_extensions.rb', line 31

def odds
  raise ArgumentError.new "You must express odds like 2:1 or 2-1" unless match /^[0-9]+(:|-)[0-9]+$/
  first, second = *split($1).map {|string| string.to_f}
  Percentage.new((second / first) * 100)
end