Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetual/fixnum.rb

Overview

– This file is part of Perpetual.

Copyright© 2012 Giovanni Capuano <[email protected]>

Perpetual is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Perpetual is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Perpetual. If not, see <www.gnu.org/licenses/>. ++

Instance Method Summary collapse

Instance Method Details

#factorialObject

Calculates the factorial of the number.



29
30
31
# File 'lib/perpetual/fixnum.rb', line 29

def factorial
  self.one? ? 1 : self * (self - 1).factorial
end

#in_wordObject Also known as: in_words

Returns the English word for the number or a empty string if the number is not known. Supports number from 0-10.



34
35
36
# File 'lib/perpetual/fixnum.rb', line 34

def in_word
  [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten' ][self] || ''
end