Sha256: f75c43da0015c2343d04cf4e9df1e6464be21d50a81551b125ddac1a06d34b81
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>. # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved. # License:: GNU General Public License (GPL). # Revision:: $Id: helpers.rb 221 2005-05-09 12:40:57Z ertai $ module Commands module Helpers class ::String # # Make a command from a String. # # Split your command when no quotations are used. # # Do not touch the String and give as one argument. def to_cmd if self =~ /['"`]/ Command.new(self) else Command.new(*split(/\s+/)) end end end # class ::String class ::Array def to_cmd Command.new(*self) end end # class ::Array end # module Helpers if __FILE__ == $0 require 'test/unit' class HelpersTest < Test::Unit::TestCase def test_string_to_cmd assert_equal(['foo', 'bar'], "foo bar".to_cmd.to_a) assert_equal(['foo', 'b/ar', 'qu44x32'], "foo b/ar \t \n qu44x32".to_cmd.to_a) s = "foo 'b/ar \t' \n qu44x32" assert_equal([s], s.to_cmd.to_a) end def test_array_to_cmd a = ['foo', "b/ar \t", "\n qu44x32"] assert_equal(a, a.to_cmd.to_a) end end # class HelpersTest end end # module Commands
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vcs-0.2.148 | ruby_ex/commands/helpers.rb |