Sha256: b0665bbea6d9229e404dcc7016c10a4c9ba52045897620a3fd47a9dae49d14c2

Contents?: true

Size: 721 Bytes

Versions: 38

Compression:

Stored size: 721 Bytes

Contents

class Array
  ##
  # Split _string_ into an array. Used in
  # conjunction with Highline's #ask, or #ask_for_array
  # methods, which must respond to #parse.
  #
  # This method allows escaping of whitespace. For example
  # the arguments foo bar\ baz will become ['foo', 'bar baz']
  #
  # === Example
  #
  #   # ask invokes Array#parse
  #   list = ask 'Favorite cookies:', Array
  #
  #   # or use ask_for_CLASS
  #   list = ask_for_array 'Favorite cookies: '
  #

  def self.parse(string)
    # Using reverse + lookahead to work around Ruby 1.8's lack of lookbehind
    # TODO: simplify now that we don't support Ruby 1.8
    string.reverse.split(/\s(?!\\)/).reverse.map { |s| s.reverse.gsub('\\ ', ' ') }
  end
end

Version data entries

38 entries across 38 versions & 6 rubygems

Version Path
commander-4.4.2 lib/commander/core_ext/array.rb
commander-4.4.1 lib/commander/core_ext/array.rb
simple_commander-0.5.1 lib/simple_commander/core_ext/array.rb
simple_commander-0.5.0 lib/simple_commander/core_ext/array.rb
simple_commander-0.4.0 lib/simple_commander/core_ext/array.rb
simple_commander-0.3.1 lib/simple_commander/core_ext/array.rb
simple_commander-0.3.0 lib/simple_commander/core_ext/array.rb
simple_commander-0.1.0 lib/simple_commander/core_ext/array.rb
simple_commander-0.0.1 lib/simple_commander/core_ext/array.rb
commander-4.4.0 lib/commander/core_ext/array.rb
commander-4.3.8 lib/commander/core_ext/array.rb
commander-4.3.7 lib/commander/core_ext/array.rb
commander-4.3.5 lib/commander/core_ext/array.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/commander-4.3.4/lib/commander/core_ext/array.rb
commander-4.3.4 lib/commander/core_ext/array.rb
commander-4.3.3 lib/commander/core_ext/array.rb
commander-4.3.2 lib/commander/core_ext/array.rb
commander-4.3.1 lib/commander/core_ext/array.rb