Sha256: 41525a681699cff97371490b1111ed8c76f492369024276343fbd09a8454fd40

Contents?: true

Size: 955 Bytes

Versions: 9

Compression:

Stored size: 955 Bytes

Contents

module English

  module Array

    # This is more advnaced form of #join. It allows for a different
    # terminating separator.
    #
    # The default type of conjunction --the terminating separator, is "and", and
    # the default regualt separator is ",".
    #
    #   [1,2,3].conjunction
    #   => "1, 2 and 3
    #
    #   [1,2,3].conjunction(:or)
    #   => "1, 2 or 3
    #
    #   [1,2,3].conjunction(:or, ';')
    #   => "1; 2 or 3
    #
    def conjunction(type=:and, seperator=",")
      type      = type.to_s
      separator = separator.to_s
      space     = space.to_s

      case length
      when 0
        ""
      when 1
        self[0]
      when 2
        "#{self[0]} #{type} #{self[1]}"
      else
        [self[0..-2].join("#{separator} "), self[-1]].join(" #{type} ")
      end
    end

    # Alias for #conjunction.
    alias_method :join_sentence, :conjunction

  end

end


class Array #:nodoc:
  include English::Array
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
etapper-0.0.5 vendor/gems/english-0.3.1/lib/english/array.rb
etapper-0.0.4 vendor/gems/english-0.3.1/lib/english/array.rb
etapper-0.0.3 vendor/gems/english-0.3.1/lib/english/array.rb
etapper-0.0.2 vendor/gems/english-0.3.1/lib/english/array.rb
etapper-0.0.1 vendor/gems/english-0.3.1/lib/english/array.rb
etapper-0.0.0 vendor/gems/english-0.3.1/lib/english/array.rb
mack-facets-0.8.2 lib/gems/english-0.3.1/lib/english/array.rb
mack-facets-0.8.3.1 lib/gems/english-0.3.1/lib/english/array.rb
mack-facets-0.8.3 lib/gems/english-0.3.1/lib/english/array.rb