Module: Cli_Yo::Helper
- Defined in:
- lib/cli_yo/helper.rb
Class Method Summary collapse
Class Method Details
.beautiful_sentence(arr) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cli_yo/helper.rb', line 17 def self.beautiful_sentence arr return nil if arr.size == 0 return arr[0] if arr.size == 1 str = "" for i in 0...(arr.size - 1) do str += ", " unless i == 0 str += "#{arr[i]}" end str = "#{str} and #{arr.last}" end |
.consecutive_counter(n) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cli_yo/helper.rb', line 3 def self.consecutive_counter n suffix = "th" unless (n >= 10 && n <= 20) || n.to_s[-2] == '1' if n.to_s[-1] == '1' suffix = "st" elsif n.to_s[-1] == '2' suffix = "nd" elsif n.to_s[-1] == '3' suffix = 'rd' end end "#{n}-#{suffix}" end |