Sha256: ca5e9fa9157e22d8b42daf470b49640c8531e637475eb45b5f95060ea75ded57

Contents?: true

Size: 667 Bytes

Versions: 10

Compression:

Stored size: 667 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
    string.reverse.split(/\s(?!\\)/).reverse.map { |s| s.reverse.gsub('\\ ', ' ') }
  end

end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
commander-4.2.1 lib/commander/core_ext/array.rb
commander-4.2.0 lib/commander/core_ext/array.rb
clone-1.0.0.beta2 module/gems/commander-4.1.3/lib/commander/core_ext/array.rb
clone-1.0.0.beta module/gems/commander-4.1.3/lib/commander/core_ext/array.rb
commander-4.1.6 lib/commander/core_ext/array.rb
taco_it-1.5.3 lib/taco/commander/core_ext/array.rb
commander-4.1.5 lib/commander/core_ext/array.rb
taco_it-1.5.2 lib/taco/commander/core_ext/array.rb
commander-4.1.4 lib/commander/core_ext/array.rb
commander-4.1.3 lib/commander/core_ext/array.rb