How to execute a Ruby script in Terminal?

前端 未结 9 1626
南笙
南笙 2020-12-04 06:15

I\'ve set everything up that I need on my Mac (Ruby, Rails, Homebrew, Git, etc), and I\'ve even written a small program. Now, how do I execute it in Terminal? I wrote the pr

9条回答
  •  旧时难觅i
    2020-12-04 07:07

    Open your terminal and open folder where file is saved.
    Ex /home/User1/program/test.rb

    1. Open terminal
    2. cd /home/User1/program
    3. ruby test.rb

    format or test.rb

    class Test 
      def initialize
       puts "I love India"
      end
    end
    
    # initialize object
    Test.new
    

    output

    I love India
    

提交回复
热议问题