Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Ruby 中似乎没有 main 函数。那么 Ruby 中 main 的等价物是什么?
Ruby 中没有这样的东西。解释器从上到下执行代码,因此您的主脚本隐含地是“main”的主体。例如,假设您有两个文件script_a.rb和script_b.rb. 并假设内容script_a.rb如下:
script_a.rb
script_b.rb
require_relative './script_b' puts 1 + 1
现在,如果您运行ruby script_a.rb,您将得到的实际代码执行如下:查找script_b.rb、执行的内容script_b.rb、执行puts 1 + 1。
ruby script_a.rb
puts 1 + 1