CSC/ECE 517 Fall 2011/ch1 2a av: Difference between revisions
Line 36: | Line 36: | ||
'''1. Purely object oriented''' | '''1. Purely object oriented''' | ||
Ruby is a purely object oriented language. There are no primitives. Everything is an object. For example, Integers, Strings, Arrays are all objects. | Ruby is a purely object oriented language. There are no primitives. Everything is an object. For example, Integers, Strings, Arrays are all objects. | ||
Line 42: | Line 43: | ||
Variables in Ruby are not assigned a type. The programmer need not declare the variable with its type before use. The type of the variable is given the type of the value it is assigned. Unlike statically types languages, there is no static compile time type checking in Ruby. | Variables in Ruby are not assigned a type. The programmer need not declare the variable with its type before use. The type of the variable is given the type of the value it is assigned. Unlike statically types languages, there is no static compile time type checking in Ruby. | ||
3. Blocks and Closures | '''3. Blocks and Closures''' | ||
Ruby supports functional programming paradigm by having blocks and closures. Blocks and Closures are explained in detail below. | |||
'''4. Built in Iterators''' | |||
Ruby supports built-in iterators that are used to traverse over a collection. Built-in iterators make programming easier and code shorter. | |||
'''5. Multiple Inheritance through Mixins''' | |||
The disadvantages of multiple inheritance are overcome in Ruby through the use of Modules and Mixins. These are similar to interfaces in Java. | |||
'''6. Unbounded Polymorphism - "Duck Typing"''' | |||
A method can be invoked on a variable whenever the type of object assigned to the variable has that method defined on it. | |||
This means that if the parameter passed to a method supports the methods invoked on it by the called method, then the calls work. | |||
This is unbounded polymorphism, which can only be found in dynamically typed languages. | |||
7. Reflection | '''7. Reflection''' | ||
8. Metaprogramming | '''8. Metaprogramming''' | ||
9. Syntax level Perl compatible for regular expressions | '''9. Syntax level Perl compatible for regular expressions''' | ||
10. Built-in support for certain Design Patterns | '''10. Built-in support for certain Design Patterns''' | ||
11. Mark-and-Sweep garbage collection | '''11. Mark-and-Sweep garbage collection''' | ||
12. OS independent threading | '''12. OS independent threading''' | ||
13. Easy interface to C modules | '''13. Easy interface to C modules''' | ||
'''14. Portable easily''' | '''14. Portable easily''' |
Revision as of 16:54, 29 September 2011
Introduction to Ruby
Ruby is a dynamic, reflective, object oriented, single-pass interpreted programming language. Ruby was influenced by Perl, Smalltalk, Eiffel and Lisp. It supports functional, imperative, reflective, object oriented and many other programming paradigms.
Ruby is said to incorporate the "Principle of Lease Surprise" or "Principle of Lease Astonishment".
History
Ruby was created in 1993 in Japan, by Yukihiro Matsumoto ("Matz"). The intent of developing Ruby was to have a new language that balance functional programming and iterative programming. Matsumoto has also stated that he wanted a scripting language that was more powerful than Perl and more Object Oriented than Python.(ref)
Naming
The terms "Coral" and "Ruby" were the two proposed names for the language. Matsumoto's choose the term "Ruby" because it was one of his colleague’s birthstone.
Releases and Versions
Ruby 0.95 was the first public release in 1995. Three more versions were released immediately.
Ruby 1.0 was released in 1996.
Ruby 1.3 was the next release in 1999.
Since then several versions of Ruby have been released with added concepts and features.
The recent stable version is Ruby 1.9.2 which has significant improvements over Ruby 1.8 series.
Currently, Ruby 1.9.3 is under development with a dual-license of Ruby and BSD.
Ruby on Rails
With the release of Ruby on Rails in 2005, an MVC based web development framework written in Ruby, the new language gained mass acceptance and became famous.
In 2006, active user groups were formed in the world's major cities and several Ruby related conferences were held, making it one of the most popular and widely acceptable language. In 2007, TIOBE programming language popularity index (link) state Ruby as the 10th most popular language.
Features
1. Purely object oriented
Ruby is a purely object oriented language. There are no primitives. Everything is an object. For example, Integers, Strings, Arrays are all objects.
2. Dynamically types
Variables in Ruby are not assigned a type. The programmer need not declare the variable with its type before use. The type of the variable is given the type of the value it is assigned. Unlike statically types languages, there is no static compile time type checking in Ruby.
3. Blocks and Closures
Ruby supports functional programming paradigm by having blocks and closures. Blocks and Closures are explained in detail below.
4. Built in Iterators
Ruby supports built-in iterators that are used to traverse over a collection. Built-in iterators make programming easier and code shorter.
5. Multiple Inheritance through Mixins
The disadvantages of multiple inheritance are overcome in Ruby through the use of Modules and Mixins. These are similar to interfaces in Java.
6. Unbounded Polymorphism - "Duck Typing"
A method can be invoked on a variable whenever the type of object assigned to the variable has that method defined on it. This means that if the parameter passed to a method supports the methods invoked on it by the called method, then the calls work. This is unbounded polymorphism, which can only be found in dynamically typed languages.
7. Reflection
8. Metaprogramming
9. Syntax level Perl compatible for regular expressions
10. Built-in support for certain Design Patterns
11. Mark-and-Sweep garbage collection
12. OS independent threading
13. Easy interface to C modules
14. Portable easily Ruby was developed on GNU/Linux. It is portable and works on several types of UNIX, DOS, BeOS, OS/2, Mac OS X, Windows 95/98/Me/NT/2000/XP/Vista/7, etc.
Downloads and Installation
The main website for Ruby is http://www.ruby-lang.org/en/.
Ruby downloads and installation instructions can be found at http://www.rubylang.org/en/downloads/. Ruby can be installed by either building it from source or by using the one-click Ruby installer for Windows. Using the one-click Rails Installer for Windows, one can install Ruby and Rails together.
One can also use Ruby online at http://www.tryruby.org/.
Interactive Ruby Browser - IRB
Once Ruby is installed, code can directly be evaluated using the IRB. IRB looks like a command line interface. It can be started in two ways:
1. Directly open the IRB by clicking on the Interactive Ruby icon.
2. In the command prompt, type "irb" to start a new IRB session.
The result of execution of the code is immediately returned in the IRB.
Other Editors for Ruby
Ruby is supported by Eclipse. It has an exclusive Ruby perspective. However, the eclipse plug-in for ruby has to be installed.
RubyMine is another Ruby editor which is commonly used for Ruby on Rails - Web development Framework.