| Start |
|---|
| Hello World This example assumes Ruby is installed. Place the following in a file named From the command line, type the following command to execute the Ruby code from the source file: This should output: The output will be immediately displayed to the console. Ruby source files don't need to be compiled before being executed. The Ruby interpreter compiles and executes the Ruby file at runtime. |
| Hello World as a Self-Executable File—using Shebang (Unix-like operating systems only) You can add an interpreter directive (shebang) to your script. Create a file called Give the script executable permissions. Here's how to do that in Unix: Now you do not need to call the Ruby interpreter explicitly to run your script. |
| Hello World from IRB Alternatively, you can use the Interactive Ruby Shell (opens new window) (IRB) to immediately execute the Ruby statements you previously wrote in the Ruby file. Start an IRB session by typing: Then enter the following command: This results in the following console output (including newline): If you don't want to start a new line, you can use |
| Hello World without source files Run the command below in a shell after installing Ruby. This shows how you can execute simple Ruby programs without creating a Ruby file: You can also feed a Ruby program to the interpreter's standard input. One way to do that is to use a here document (opens new window) in your shell command: |
| Hello World with tk Tk is the standard graphical user interface (GUI) for Ruby. It provides a cross-platform GUI for Ruby programs. Example code:The result: Step by Step explanation: Load the tk package. Define a widget with the title Start the main loop and display the widget. |
My First Method OverviewCreate a new file named Place the following code inside the file: Now, from a command line, execute the following: The output should be: Explanation
RemarksRuby (opens new window) is a multi-platform open-source, dynamic object-oriented interpreted language, designed to be simplistic and productive. It was created by Yukihiro Matsumoto (Matz) in 1995. According to its creator, Ruby was influenced by Perl (opens new window), Smalltalk (opens new window), Eiffel (opens new window), Ada (opens new window), and Lisp (opens new window). It supports multiple programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management. |
Read Article
https://develop.horje.com/learn/1434/reference