Class: Array

Inherits:
Object show all
Defined in:
lib/util.rb,
lib/lowline.rb

Instance Method Summary collapse

Instance Method Details

#first_duplicateObject



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_hObject



30
31
32
# File 'lib/util.rb', line 30

def to_h
  Hash[*flatten]
end