简体   繁体   English

如何在Rails控制台中执行ruby命令(例如执行ruby脚本)?

[英]How do I execute a ruby command (such as to execute a ruby script) from within the Rails console?

From within the Rails console, I would like to execute a ruby script, eg setup_for_experimenting.rb, that creates objects for and then executes the ruby program that I want to experiment with. 在Rails控制台中,我想执行一个ruby脚本,例如setup_for_experimenting.rb,该脚本为该对象创建对象,然后执行我想尝试的ruby程序。 The program I'm experimenting with is a service that is not yet completely written and has no tests yet, either, but I can execute it from within rails console. 我正在尝试的程序是一个尚未完全编写且还没有测试的服务,但是我可以在rails控制台中执行它。

How do I do give the command ruby setup_for_experimenting.rb from within the rails console? 如何从Rails控制台中发出命令ruby setup_for_experimenting.rb

You can add any plain ruby file inside the console with require 您可以使用require在控制台内添加任何纯红宝石文件

So in your case inside hte console 因此,在您的情况下,在HTE控制台中

require "./setup_for_experimenting.rb"

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

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