Class: Array

### Home Classes Methods

### In Files

- lib/commander/core_ext/array.rb

### Parent

Object

### Methods

- ::parse

### Class/Module Index

Quicksearch

- Commander
- Commander::Command
- Commander::Command::Options
- Commander::Delegates
- Commander::HelpFormatter
- Commander::HelpFormatter::Base
- Commander::HelpFormatter::Terminal
- Commander::HelpFormatter::TerminalCompact
- Commander::Platform
- Commander::Runner
- Commander::Runner::CommandError
- Commander::Runner::InvalidCommandError
- Commander::UI
- Commander::UI::AskForClass
- Commander::UI::ProgressBar
- Array
- Blank
- Object

No matching classes.

# Array

### Public Class Methods

parse(string) click to toggle source

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: '

    # File lib/commander/core_ext/array.rb, line 21
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.