Example I have the file test.rb:
puts "test test test"
How do I run this file in the ruby console?
load("test.rb")
应该在irb
。
load 'test.rb'
Do you mean Rails console? (Same thing, but the question is tagged rails.)
On Mac you can run in three different ways from the terminal Method 1 On Terminal irb (Interactive Ruby Shell) for line by line execution then quit command to be out of irb.
Method 2 As ruby is Interpreted language we can run by one command on terminal
Method 3 ruby -v to know the version of ruby ruby -e 'puts WVU' #line by line execution on terminal
Any ruby file can be run with just ruby <your_ruby_file.rb>
, supposing that you are in the same directory as the ruby file; If not, just provide a path to the file:
ruby path/to/your_file.rb
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.