Sha256: e1593a8a8955b6d68b4a6c97e42ba557868e304e4539aa6a457b9517d5617893
Contents?: true
Size: 686 Bytes
Versions: 18
Compression:
Stored size: 686 Bytes
Contents
class Array def sum inject(0, :+) end # For some reason .to_h doesn't show as defined in opal, but defined?(:to_h) # returns true. def to_h Hash[self] end # Converts an array to a sentence def to_sentence(options={}) conjunction = options.fetch(:conjunction, 'and') comma = options.fetch(:comma, ',') oxford = options.fetch(:oxford, true) # <- true is the right value case size when 0 '' when 1 self[0].to_s when 2 self.join(" #{conjunction} ") else str = self[0..-2].join(comma + ' ') str += comma if oxford str += " #{conjunction} " + self[-1].to_s str end end end
Version data entries
18 entries across 18 versions & 1 rubygems