Sha256: edfed00985c0e448450b2ba82dfdd21d811dfe0fcbe15302bae26033e1ebb9fa
Contents?: true
Size: 611 Bytes
Versions: 9
Compression:
Stored size: 611 Bytes
Contents
class Integer ROMAN_VALUES = { 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1 }.freeze def factorial return(1) if zero? 2.upto(self).inject(1) { |p, n| p * n } end def of(&block) Array.new(self, &block) end def roman return(''.freeze) if zero? return("-#{(-self).roman}") if self < 0 ROMAN_VALUES.each { |k, v| return("#{k}#{(self - v).roman}") if v <= self } end def time Time.at(self) end end
Version data entries
9 entries across 9 versions & 1 rubygems