Class: Array
- Defined in:
- lib/volt/extra_core/array.rb,
lib/volt/extra_core/blank.rb
Instance Method Summary collapse
- #sum ⇒ Object
-
#to_h ⇒ Object
For some reason .to_h doesn’t show as defined in opal, but defined?(:to_h) returns true.
-
#to_sentence(options = {}) ⇒ Object
Converts an array to a sentence.
Instance Method Details
#sum ⇒ Object
2 3 4 |
# File 'lib/volt/extra_core/array.rb', line 2 def sum inject(0, :+) end |
#to_h ⇒ Object
For some reason .to_h doesn’t show as defined in opal, but defined?(:to_h) returns true.
8 9 10 |
# File 'lib/volt/extra_core/array.rb', line 8 def to_h Hash[self] end |
#to_sentence(options = {}) ⇒ Object
Converts an array to a sentence
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/volt/extra_core/array.rb', line 14 def to_sentence(={}) conjunction = .fetch(:conjunction, 'and') comma = .fetch(:comma, ',') oxford = .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 |