Ruby on Rails Introduction - Ruby on Rails

What is Ruby?

Ruby is the combination of the goodness of

  • conceptual elegance of Smalltalk,

  • easiness in usage and learning of Python, and

  • pragmatism of Perl.

Ruby is

  • A high-level programming language.

  • Interpreted like Perl, Python, Tcl/TK.

  • Object-oriented like Smalltalk, Eiffel, Ada, Java.

Why Ruby?

Originated in Japan, Ruby is popular in US and Europe as well now because of its features like

  • Ease of learning

  • Open source

  • Rich libraries

  • Easily extendable

  • Truly object-oriented

  • Less coding with less bugs

  • Supportive community

What are the drawbacks of Ruby?

  • Performance Issues − Although it beats Perl and Python, it is still an interpreted language unlike high-level programming languages like C or C++.

  • Threading model − Ruby does not use native threads. The threads are simulated in the VM and are not run as native OS threads.

Sample Ruby Code

Here is the Ruby code to print "Hello Ruby"


The output will be:

What is Embedded Ruby?

Ruby provides a program called ERB (Embedded Ruby), which allows you to put Ruby codes inside an HTML file. ERB reads along, word for word until it encounters a Ruby code embedded in the document and starts executing the Ruby code thereon.

You need to know a few things to prepare an ERB document −

  • If you want some Ruby code executed, enclose it between <% and %>.

  • If you want the result of the code execution to be printed out, as a part of the output, enclose the code between <%= and %>.

Let us go through an example. Save the code in erbdemo.rb file.

Note: A Ruby file will have an extension .rb

Now, run the program using the command-line utility erb.

This will produce the output as −

What is Rails?

  • A highly productive web-application framework.

  • Written in Ruby by David Heinemeier Hansson.

  • Can develop a web application at least ten times faster with Rails than with a typical Java framework.

  • An open source Ruby framework for developing database-backed web applications.

  • Configure your code with Database Schema.

  • No compilation phase required.

Full Stack Framework

  • Compilation of everything needed to create a database-driven web application, using the Model-View-Controller pattern.

  • Being a full-stack framework means all the layers are built to work seamlessly together with less code.

  • Fewer lines of code compared to other frameworks.

Convention over configuration

  • Rails shuns configuration files in favor of conventions, reflection, and dynamic runtime extensions.

  • Your application code and your running database comprises of everything that Rails needs to know!

What are the strengths of Rails?

The following features of Rails makes it more productive.


Rail framework uses Metaprogramming techniques to write programs as against other frameworks which use extensive code generation from scratch. Ruby is one of the best languages for Metaprogramming, and Rails uses this capability well. Rails also uses code generation but relies much more on Metaprogramming for the heavy lifting.

Active Record

The Active Record framework of Rails saves objects into the database. The Rails version of the Active Record discovers the columns in a database schema and automatically attaches them to your domain objects using metaprogramming.

Convention over configuration

If you follow the suggested naming conventions, Rails doesn't need much configuration unlike most web development frameworks for .NET or Java, which forces you to write pages of configuration code.


You often create temporary code in the initial stages of development to help get an application up quickly and see how things work together. Rails automatically creates much of the scaffolding you'll need.

Built-in testing

Rails provides built in features that creates extendable simple automated tests. It has an additional supporting code called harnesses and fixtures that make test cases easier to write and run. Ruby can then execute all your automated tests with the rake utility.

Three environments

Rails gives you three default environments namely, development, testing, and production. Each behaves slightly differently thus making your entire software development cycle easier like, Rails creates a fresh copy of the Test database for each test run.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Ruby on Rails Topics