Sha256: d20bf35f5aa33a12a3130fecaffe17c910ed23926eed692caec8307c11e9261f
Contents?: true
Size: 752 Bytes
Versions: 2
Compression:
Stored size: 752 Bytes
Contents
# frozen_string_literal: true 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
commander-5.0.0 | lib/commander/core_ext/array.rb |
commander-4.6.0 | lib/commander/core_ext/array.rb |