How to run Ruby code from terminal?

前端 未结 2 505
半阙折子戏
半阙折子戏 2021-01-30 03:53

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?

相关标签:
2条回答
  • 2021-01-30 04:14

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

    ruby -e "puts 'hi'"
    

    Check the man page for more information.

    0 讨论(0)
  • 2021-01-30 04:15

    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.

    0 讨论(0)
提交回复
热议问题