Ruby® Notes for Professionals


This Ruby® Notes for Professionals book is compiled from Stack Overflow Documentation, the content is written by the beautiful people at Stack Overflow. Text content is released under Creative Commons BY-SA, see credits at the end of this book whom contributed to the various chapters. Images may be copyright of their respective owners unless otherwise specified

Chapter 1: Getting started with Ruby Language

Section 1.1: Hello World 

This example assumes Ruby is installed.

Place the following in a file named hello.rb:

puts 'Hello World'

From the command line, type the following command to execute the Ruby code from the source file:

$ ruby hello.rb

This should output:

Hello World

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.

Section 1.2: 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 hello_world.rb which contains:

#!/usr/bin/env ruby

puts 'Hello World!'

Give the script executable permissions. Here's how to do that in Unix: 

$ chmod u+x hello_world.rb

Now you do not need to call the Ruby interpreter explicitly to run your script. 

$ ./hello_world.rb


Continue Reading

Get this whitepaper right in your inbox for free. We never spam!

Click on the "Register With LinkedIn" button to subscribe and continue reading this whitepaper. by clicking on this button you agree to our privacy policy, coockie policy.

Editors' Pick

Boost your email marketing process with ICRM Mailbooster

Using ICRM Mailbooster you can boost your daily sending limits by configuring multiple smtp servers like aws ses, sparkpost, sendgrid, etc and reach out more subscribers daily.