Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Discussion on Ruby : An object oriented language

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 492
    Comment on it

    Welcome to Findnerd. Today we are going to discuss Ruby. Ruby is a programming language which supports object oriented programming structure. Ruby is developed or created in japan by Yukihiro "Matz" mastumoto in 1995. It uses similar syntax like Perl, Python, Smalltalk etc. It is more powerful than Perl and more object oriented than Phython. It is an interpreted language not a compiled language like Java,C++ etc. Ruby requires ruby interpreter to run the program.


    Ruby uses easily readable code like English. There are easy syntax. naming as well as behavior. It does not require semicolons in the code and It is whitespace independent. If you add extra space or white-spacing then it will not affect the code anymore. If you have worked other programming language then you will find ruby easy to use and easy to understand.


    Ruby on rails is a famous framework which is written in Ruby. Ruby on rails is for web development applications but on other side Ruby is a multipurpose language not only for web. You can simply install the Ruby on windows using one click installer and on Linux we need to run the below command. Please have a look.


    sudo apt-get install ruby-full



    There are three different ways to use the Ruby. Please have a look.


    A) ruby file


    B) single command


    C) Interactive Ruby Shell(IRS)


    Through single command we can simply run the Ruby code. We are consider that you have installed the Ruby on your system. Open the terminal and run the below command.


    ruby -v


    Above command will print the current working version of Ruby. Currently we are using ruby 1.9.3. Kindly run the below command now.



    ruby -e 'puts 534'


    Above command will print the value 534 on terminal and add the line break as well. Now we will check other method that is print. Please have a look.


    ruby -e 'print 5443'



    Above command will not add the line break in the end and print the value. Kindly check the terminal screen-shot below.



    Now we will use these methods in ruby file. Kindly create a file named demo.rb and paste the below code.


    # demo.rb
    puts 343
    print 341
    puts 342


    You can put the comments using # character and run the file using below command. Please have a  look.


    // go to file directory
    ruby demo.rb



    Now we will discuss the interactive ruby shell(irb) which is nothing but a command line tool for ruby. You can test the code using irb. Run the below command to activate the irb. Please have a look.





    Now you can perform the arithmetic operations like addition, subtraction etc. You can also use the ruby methods like print, puts, reverse etc. You can also check the screen-shot for more clear idea.



    You need to press quit and hit enter to exit from the irb.


    Ruby provides us good documentation on its website you can check the documentation on below link.




    You can also check the documentation using command line. You can run the command like below.


    ri String#upcase



    Above command will provide us the details and its uses. You can exit it by pressing q.


    Thank you for being with us!

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: