GithubHelp home page GithubHelp logo

ruby_scripts's Introduction

#Basics of Ruby Scripts

Ruby started as an object-oriented scripting language. As it's popularity grew as a general-purpose programming language, the scripting aspect was largely overshadowed.

In this tutorial, I will present the basics of Ruby Scripting.

  1. Create a file ruby_script.rb. One can also have a .sh extension as that of a Unix shell script.

  2. On the command line, navigate to the directory holding the file. Then grant the execute permissions to the file.

     chmod +x ruby_script.rb
    

    With that, we are good to go.

  3. Open the file in a text editor. The first thing we ought to do is instruct the parent shell to use ruby interpreter to execute our script. This is what shebang are for. So, the first line of our script should always be

#! /usr/bin/env ruby
  1. With the interpreter assigned, we can now fill our scripts with ruby statements. Let's have the traditional Hello World script. For that, your script should look like this:
 #! /usr/bin/env ruby
 # my first hello world script
 puts 'Hello World'
  1. Now just run the script. Open the terminal and run the following:
./ruby_script.rb

You should have the greeting displayed in the terminal.

ruby_scripts's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.