繁体   English   中英

运行Ruby脚本/程序并在命令行中进行交互

[英]Running Ruby Script/Program and interacting in command line

我以前看过,但我不记得在哪里。 我有一个Ruby程序,我想在命令行中执行并与之交互并调用这些函数。 与irb类似,但在该程序中。 例如:

class Message
  @@messages_sent = 0
  def initialize (from, to)
    @from = from
    @to = to
    @@messages_sent +=1
  end   
end
class Email < Message
  def initialize (from,to)
   super
  end
end

我想运行脚本并调用诸如

my_message = Message.new('NYC','TDOT') 

怎么样? 我做了ruby myprogram.rb,然后运行并关闭它,我实际上是想进入程序

您需要首先要求IRB,然后在要启动它的位置键入IRB.start

require 'irb'

IRB.start

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM