Ruby

What is Ruby

Ruby is an object-oriented programming language. It was created in 1993 by Yukihiro Matsumoto of Japan. Ruby is a general-purpose, interpreted programming language like PERL and Python.

What is IRb

  • Interactive Ruby (IRb) serves as a shell for experimentation. Within the IRb shell, you can immediately view expression results, line by line.
  • This tool comes with Ruby installation, so no extra installations required to have IRb working. Just type irb at your command prompt and an Interactive Ruby Session will start.

Ruby Syntax

  • Whitespace characters such as spaces and tabs are generally ignored in Ruby code, except when they appear in strings.
  • Ruby interprets semicolons and newline characters as the end of a statement. However, if Ruby encounters operators, such as (+, -, or \) at the end of a line, they indicate the continuation of a statement.
  • Identifiers are names of variables, constants, and methods. Ruby identifiers are case-sensitive. Which mean “Computer” and “COMPUTER” are two different identifiers in Ruby.
  • Ruby comments start with a pound/sharp symbol (#) character and go to EOL.

General Syntax Rules

  • Comments start with a pound/sharp (#) character and go to EOL.Ruby programs are a sequence of expressions.
  • Each expression is delimited by semicolons(;) or newlines unless obviously incomplete (e.g. trailing ‘+’).
  • Backslashes at the end of line does not terminate expression.

Reserved Words in Ruby

BEGIN do next Then
END else nil TRUE
alias elsif not Undef
and end or Unless
begin ensure redo Until
break FALSE rescue when
case for retry while
class if return Def
in self __FILE__ defined?
module super __LINE__

Basic Data types

Basic types are numbers, strings, ranges, regexen, symbols, arrays, and hashes. Also included are files because they are used so often.

Leave a comment