Module: ScoutAgent::CoreExtensions::Array

Defined in:
lib/scout_agent/core_extensions.rb

Overview

Extensions for the Array class.

Instance Method Summary collapse

Instance Method Details

#to_word_list(conjuction = "and") ⇒ Object

This method converts an Array into a human readable word list String. These lists are of the form:

one
one and two
one, two, and three
etc.

You can change the conjuction used to join the last two elements.



29
30
31
32
33
34
35
36
37
# File 'lib/scout_agent/core_extensions.rb', line 29

def to_word_list(conjuction = "and")
  case size
  when 0 then ""
  when 1 then self[0].to_s
  when 2 then join(" #{conjuction} ")
  else        ( self[0..-3] +
                [self[-2..-1].join(", #{conjuction} ")] ).join(", ")
  end
end