Sha256: ad5881519230777840edd4a63a072973014a889f9c831552712716a67f36e400

Contents?: true

Size: 623 Bytes

Versions: 1

Compression:

Stored size: 623 Bytes

Contents

module DaHuang
  module ArrayExt
    def to_hash
      map { |e| yield e }.inject({}) { |carry, e| carry.merge! e }
    end

    def strip_each
      self.map{|t| t.strip}
    end
    def strip_each!
      self.each{|t| t.strip!}
    end

    def to_sentence
      i = size
      if size<=2
        self.join(" and ")
      else
        [self[0..size-2].join(", "), self[size-1]].join(" and ")
      end
    end

    def map_with_index
      result = []
      self.each_with_index do |elt, idx|
        result << yield(elt, idx)
      end
      result
    end

    def strip_all
      map!{|t| t.strip}
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
da_huangs_ruby_extensions-0.0.7 lib/array_ext.rb