为什么在控制台上抑制Ruby输出?

Bru*_*uno 0 ruby

# code.rb
def hello
  puts "hello"
end

:$ ruby code.rb
Run Code Online (Sandbox Code Playgroud)

控制台上没有输出任何内容!我正在使用Ubuntu 13.04.

如果我在IRB中运行相同的代码,它的工作原理!

Stu*_*son 5

你必须调用你的代码,你只需要定义一个方法:

    # code.rb
    def hello
      puts "hello"
    end

    hello

$ ruby code.rb
Run Code Online (Sandbox Code Playgroud)