From 9dc875f2460433e5f69eaf0a2dbb560e414db789 Mon Sep 17 00:00:00 2001 From: Tomoyuki Sahara Date: Fri, 23 Aug 2013 16:00:08 +0900 Subject: add `cmd` (command output expression). --- mrblib/kernel.rb | 4 ++++ test/io.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/mrblib/kernel.rb b/mrblib/kernel.rb index 11ac5785f..484b50160 100644 --- a/mrblib/kernel.rb +++ b/mrblib/kernel.rb @@ -1,4 +1,8 @@ module Kernel + def self.`(cmd) + IO.popen(cmd) { |io| io.read } + end + def open(file, *rest, &block) raise ArgumentError unless file.is_a?(String) diff --git a/test/io.rb b/test/io.rb index 727c67303..315f3ea79 100644 --- a/test/io.rb +++ b/test/io.rb @@ -232,6 +232,10 @@ assert('IO#fileno') do io.closed? end +assert('`cmd`') do + assert_equal `echo foo`, "foo\n" +end + assert('IO TEST CLEANUP') do assert_nil MRubyIOTestUtil.io_test_cleanup end -- cgit v1.2.3