Class: Array
Instance Method Summary collapse
Instance Method Details
#first_duplicate ⇒ Object
25 26 27 28 |
# File 'lib/util.rb', line 25 def first_duplicate sa = sort (1 .. sa.length).argfind { |i| (sa[i] == sa[i - 1]) && sa[i] } end |
#listify(prefix = "") ⇒ Object
23 24 25 26 27 28 |
# File 'lib/lowline.rb', line 23 def listify prefix="" return "" if empty? "\n" + map_with_index { |x, i| x.to_s.gsub(/^/, "#{prefix}#{i + 1}. ") }. join("\n") end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/util.rb', line 30 def to_h Hash[*flatten] end |