Class: Array
Instance Method Summary collapse
Instance Method Details
#first_duplicate ⇒ Object
33 34 35 36 |
# File 'lib/util.rb', line 33 def first_duplicate sa = sort (1 .. sa.length).argfind { |i| (sa[i] == sa[i - 1]) && sa[i] } end |
#flatten_one_level ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/util.rb', line 42 def flatten_one_level inject([]) do |ret, e| case e when Array ret + e else ret << e end end end |
#listify(prefix = "") ⇒ Object
30 31 32 33 34 35 |
# File 'lib/lowline.rb', line 30 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
38 39 40 |
# File 'lib/util.rb', line 38 def to_h Hash[*flatten] end |