Ruby is an object-oriented metaprogramming language that surprised many developers and even raises the question: is there a really better language than Java and C? This article will give a preliminary discussion on the ruby language and try to answer this question.
I. Introduction
Have you ever heard of Ruby? Today, it has become a popular topic in the software development field. This language caught my attention at a Java conference last spring. Famous figures like Bruce Tate and Dave Thomas talked about Ruby and told the audience that Ruby was worth watching.
Now, if you are engaged in software development like I do, we have a consensus: Although learning a new programming language may be interesting, but after you have a deep understanding of it, you are qualified to look at another programming language with a skeptical view. After all, the competition for programming languages in the S and finally concluded that there are two camps: the Java World and the development language supported by Microsoft Based on. NET. Not that I don't want to learn another language. In fact, I just hope that the day will soon end when I want to gain some technical advantages by choosing other programming languages. However, due to the influence of several famous people, I decided to try Ruby.
Well, if "I have reached the top of the hill", this article is my research report on Ruby.
Ii. Install Ruby
Ruby is an open-source programming language developed by yukihiro Matsumoto of Japan in the middle of 1990s. You can get Ruby at www.ruby-lang.org sites. This language was initially created as a scripting language and can be applied to many platforms, including Linux, various types of UNIX, MS-dos, windows, BEOs, amiga, Acorn risc OS, and MacOS X. The latest Ruby version is 1.8.4. For Windows users, click here to get a "one-click" Windows installer. Along with basic Ruby binaries and library files, this download also contains some useful (and free) IDE and tools, including help documentation and sample code, rubygems Package Manager, freeride (free Ruby IDE), Fox GUI library, fxri (a GUI guide for search engines and Ruby documentation, and an interactive command line tool) and scite (scintilla text editor IDE ). When writing this article, the ruby "stable" version provided by the Windows Installer is 1.8.2, and a preview version of 1.8.4 is also available. Note that the sample code in this article is written in version 1.8.2 provided by the Windows installer.
Using the Windows installer to install Ruby is quite straightforward. You only need to download and run a simple executable Installation File (ruby182-15.exe), this program will start a standard installation wizard. The downloaded file is about 15 MB. After Ruby is installed on Windows, the wizard occupies about 40 MB of hard disk space.
For programmers who prefer their own editors, a large number of editors provide Ruby support, including Emacs, Vim, jedit, Jed, nedit, and textpad. Of course, there is also a famous Ruby Eclipse project. Ruby development tool (RDT) is an Eclipse plug-in that is still under development in the early stages, but you can download and try it from here. In addition, there are some cheap Ruby Ides on the market, among which arachno Ruby is one.
Run Ruby
Like many explanatory languages, Ruby provides programmers with a variety of code development methods. You can use the command line tool to run Ruby interactively or create a ruby program file, and then require the Ruby interpreter to execute this program.
In Windows, open the command line Prompt window, enter "Ruby" in the prompt, and press enter (Note: You should be able to locate the ruby executable file along the ruby/bin directory ). Then Ruby will run and wait for you to enter the program. Enter the following program, press Ctrl + D, and then press Enter. You will see Ruby executing your program, as shown in 1.
Def convertctof (Celsius) Print (Celsius. to_s + "degrees Celsius is" + (Celsius * 9)/5 + 32). to_s + "degrees in Fahrenheit/N ") End Convertctof (20) |
Figure 1. Interactive computing of temperature conversion from Celsius to Fahrenheit in ruby
The Conversion Program in Figure 1 can also be implemented and saved to a file using a ruby ide or a simple text editor-for example, convertctof. Rb (. Rb is a common file type for Ruby programs ). Now, the Ruby interpreter will execute the ruby program in this file, as shown in figure 2.
Figure 2. Run convertctof. Rb
Users familiar with smalltalk, Common LISP Object System (clos), or other explanatory programming environments are certainly familiar with interactive development environments. Interaction Features allow you to experiment with small pieces of programming code. By using a special Ruby batch processing file IRB. bat, you can overcome the non-interactive features of the Ruby interpreter. Figure 3 shows Ruby started with the IRB. Bat command. Now, the code can be input, interpreted, and tested line by line.
Figure 3. Interactive Ruby
Interactive Ruby features are also embedded into several tools. For example, the graphic interface fxri of the Ruby document can be used not only as a language guide, but also as an interactive Ruby interpreter (see figure 4 ).
Figure 4. fxri's interactive Ruby capabilities: Here, fxri is also used to run the same Ruby commands as Figure 3, but this is run within the document tool.