How to Write a Ruby Script

The Ruby programming language represents an object-oriented way in which to develop applications, usually for use on the Web. Through Ruby, programmers can create active, animated and responsive Web pages that users can interact with. One of Ruby's strength is its ease of use. With very little introduction a newcomer to Ruby programming can begin writing Ruby scripts.

Things You'll Need

  • Text Editor
Show More

Instructions

    • 1

      Check for the Ruby interpreter. Some Linux systems come with Ruby preinstalled. In a command terminal type the following command:

      ruby -v

      If ruby exists on the computer this command will return a version number. If not you can download and install Ruby from ruby-lang.org/en/downloads/.

    • 2

      Create a script in your text editor. Each ruby script written in the text editor will begin with the "shebang" line that denotes the location of the ruby files. If your ruby installation exists in "/usr/bin" for example your script will start with this first line:

      #!/usr/bin/ruby

    • 3

      Write the "Hello World" program. The ruby version of this program only consists of one line as in the following example:

      #!/usr/bin/ruby
      puts "Hello World!"

    • 4

      Save the file as "hello.rb" and execute it from the command line with the following command:

      > ruby hello.rb
      Hello World!

Related Searches:

References

Comments

Related Ads

Featured