How to run ruby on terminal using sublime

喜夏-厌秋 提交于 2021-02-08 21:51:25

问题


I'm not even sure if this question is right.

I'm doing a ruby tutorial on the following link www.youtube.com/watch?v=Dji9ALCgfpM

And he writes code on sublime, and the ran code is shown on terminal. I used to do berry thing on integrative ruby, irb. What's the difference?


回答1:


You have two main options:

The first option is to run the Ruby code in your terminal. Save your Ruby file as somename.rb. In your terminal, navigate to the directory you saved it in, and then simply run it with

ruby somename.rb

It should then run nicely. Do make sure you have Ruby installed on your system first, otherwise look here

Alternatively you can run it right there in Sublime Text. Make sure you're in Ruby mode by clicking on the language selector in the bottom-right corner of the screen.

Also - in the top menu go to Tools -> Build System -> Ruby

From then on, you can run it right there in Sublime by pressing Tools -> Build, or using the CTRL-B hotkey.




回答2:


There is no connection with terminal and sublime. Sublime is a text editor, there is an option to build your program there(sublime) using ctrl + b, but if you are getting user input at run time then the file just gets build but doesn't run.

If you want to run your ruby file in terminal:

Write your code in sublime or any other text editors and save the file with extension (.rb). In terminal , if you have installed ruby, type irb filename.rb. But before that check the current directory is set to the file location. If not change directory using cd command that is cd filepath.

Running a sample ruby file in terminal using irb:

Running a sample ruby file in sublime:




回答3:


You create your Ruby program in a file :

my_first_ruby_program.rb

You put some content in it:

puts "Hello world"

Then you execute your program by launching it in the console (assuming you're in the same directory as the file/ruby program you have created):

ruby my_first_program.rb

irb is an interactive shell, it's useful for testing some short programs or lines of code. When you want to make a "full" program/script you want to save it into a file. Then you can execute it.

Some links:

Make your first ruby file (middle of the post)

More about IRB

learn more about ruby and ror:

Ruby tutorial

Rails tutorial



来源:https://stackoverflow.com/questions/31185417/how-to-run-ruby-on-terminal-using-sublime

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