Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/kin/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#numericise(amount) ⇒ String

Pluralises self according to the amount.

Examples:

With zero

0.numericise('heffalump') # => "no heffalumps"

With one

1.numericise('heffalump') # => "one heffalump"

With two

2.numericise('heffalump') # => "2 heffalumps"

Parameters:

  • amount (Integer)

    The number of things.

Returns:

  • (String)

    The pluralised word.



17
18
19
20
21
22
23
# File 'lib/kin/core_ext/string.rb', line 17

def numericise(amount)
  case amount
    when 0, nil then "no #{plural}"
    when 1      then "one #{self}"
    else             "#{amount.to_s} #{plural}"
  end
end