Ruby Command Line

  • ruby -v – Tells us which version of Ruby is installed.
  • which ruby – Tells us where Ruby is located on the system.
  • ruby -e ‘puts 94118’ – Used to run a single line of Ruby.
  • ruby test.rb – Used to execute/run a Ruby file.
  • ri String#upcase – ri stands for Ruby Information. Used for getting documentation which is stored locally on the system on all the different classes and methods and files that are available to us in Ruby.

Introducing Ruby

What is Ruby?

Ruby is a programming language that was created in Japan, in 1995, by Yukihiro Matsumoto (Matz). Ruby has a syntax similar to Perl, Python, and Smalltalk. Ruby is not a compiled language (like C++, Java, Visual Basic). A compiled language is a language where you write the code and then you have to run it through compiler in order to come out with an application that you can actually run at the end. Instead Ruby is an interpreted language and requires a Ruby interpreter to execute the code.

Why Ruby?

Ruby is an object-oriented language – almost everything in Ruby is an object. An object is the fundamental building block in Ruby. Ruby also has easily readable code. It reads a lot like English. So we don’t spend a lot of time trying to decipher the code to understand what our program is doing. Ruby also has an unsurprising syntax, naming, and behavior to it. Ruby is white space independent (extra tabs or extra spaces doesn’t really make a difference). Unlike a lot of languages, there are no semi-colons.

Ruby VS. Ruby on Rails

  • Ruby on Rails
    • Web framework written in Ruby that is used for building websites
  • Ruby
    • Multipurpose language
    • Not just for the Web