Implement Shellwords.split

Submitted By:
znz

Difficulty:
Medium

Tags:
strings

Instructions:
Re-implement Ruby's Shellwords.shellsplit.

Code:
module Shellwords
  def shellsplit(line)
    ___
  end
  module_function :shellsplit
  class << self
    alias split shellsplit
  end
end

assert_equal Shellwords.split('here are "two words"'), ["here", "are", "two words"]
assert_equal Shellwords.split(%q{  foo bar "foo bar"\ baz 'foo bar'  }), ["foo", "bar", "foo bar baz", "foo bar"]
assert_equal Shellwords.split(%q{  A B C "D E F" "G","H I"  }), ["A", "B", "C", "D E F", "G,H I"]
assert_equal Shellwords.split('grep Jan\ 15 file\ name\ with\ spaces'), ["grep", "Jan 15", "file name with spaces"]

Your Solution

Ruby 1.9.3

Back to Problems