Module: IntegerExtensions

Defined in:
lib/ruby_extensions.rb

Constant Summary collapse

PRIMES =
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349].freeze

Instance Method Summary collapse

Instance Method Details

#hphObject



62
63
64
65
66
67
# File 'lib/ruby_extensions.rb', line 62

def hph
  n = self
  return 1 if n == 1

  PRIMES.reverse.find{|p| n.gcd(p) != 1 }
end

#ordinalizeObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby_extensions.rb', line 47

def ordinalize
  n = self
  return "#{n}th" if (11..13).include?(n % 100)

  case n % 10
  when 1 then "#{n}st"
  when 2 then "#{n}nd"
  when 3 then "#{n}rd"
  else "#{n}th"
  end
end