Sha256: 46c2d611e39692f10f49b00643e1df22f200c2ee1d5442c97c1912ab0a4dd535
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
class Array def to_csv ret = [] for row in self add = [] for el in row add << '"'+el.to_s.gsub(/\s+/,' ').gsub(/"/,"''")+'"' end ret.push(add.join(';')) end ret.join("\n") end def wrap(name, opts={}) map{ |el| opts.tag(name, opts) } end def last=(what) self[self.length-1] = what end def to_sentence(opts={}) opts[:words_connector] ||= ', ' opts[:two_words_connector] ||= ' and ' opts[:last_word_connector] ||= ', and ' len = self.length return '' if len == 0 return self[0] if len == 1 return self.join(opts[:two_words_connector]) if len == 2 last_word = self.pop self.join(opts[:words_connector]) + opts[:last_word_connector] + last_word end # toggle element in array and return true when added def toggle(element) self.uniq! self.compact! if self.include?(element) self.delete(element) false else self.push(element) true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lux-fw-0.1.17 | ./lib/overload/array.rb |