Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/na/array.rb

Direct Known Subclasses

NA::Actions

Instance Method Summary collapse

Instance Method Details

#remove_badArray

Like Array#compact – removes nil items, but also removes empty strings, zero or negative numbers and FalseClass items

Returns:

  • (Array)

    Array without “bad” elements



10
11
12
# File 'lib/na/array.rb', line 10

def remove_bad
  compact.map { |x| x.is_a?(String) ? x.strip : x }.select(&:good?)
end

#wrap(width, indent, color) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/na/array.rb', line 14

def wrap(width, indent, color)
  return map { |l| "#{color}  #{l.wrap(width, 2)}" } if width < 60

  map! do |l|
    "#{color}#{' ' * indent }#{l.wrap(width, indent)}{x}"
  end
  "\n#{join("\n")}"
end