How to run Ruby code from terminal?

依然范特西╮ 提交于 2020-11-30 02:15:05

问题


I need to run a few lines of Ruby code from terminal, but I can't find the needed parameter for it.

Can you explain how to do this?


回答1:


If Ruby is installed, then

ruby yourfile.rb

where yourfile.rb is the file containing the ruby code.

Or

irb

to start the interactive Ruby environment, where you can type lines of code and see the results immediately.




回答2:


You can run ruby commands in one line with the -e flag:

ruby -e "puts 'hi'"

Check the man page for more information.



来源:https://stackoverflow.com/questions/12378818/how-to-run-ruby-code-from-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!