![]() |
Introduction To Ruby
The Ruby-interpreted scripting language is an easy-to-learn environment for quickly developing object-oriented applications. Learn more about Ruby in this article from Builder.com
Most frequently compared to Smalltalk, Python, Perl, C++, and Java, Ruby is a useful tool for rapid development and creation of prototypes. This article introduces Ruby and provides a simple script to illustrate its familiar and powerful syntax. Ruby highlightsRuby was created in 1995 by Japanese national Yukihiro Matsumoto as a way to easily process text and create system management tools. Since then, it has rapidly grown in popularity, thanks to its unique object-handling and inheritance structure. In Ruby, everything is an object. For example, if you were to assign a variable with a value of 42, the number 42 itself is an instance of the integer object class, which is then stored as a value. Standard classes are user-extensible, giving the language ultimate flexibility. Additionally, C++ and Ruby classes can be inherited on the fly, enabling applications to make use of functions that Ruby itself doesn't provide. All variables are assigned and typed at run time. This eliminates the need for predefining variables, although mechanisms are available for specifically typing values if necessary. This also means that special syntax is not used to tell Ruby what type a variable is. For example, while @varname represents an array in Perl, typing is purely contextual in Ruby. In contrast, syntax is used to control a variable's scope. For example, variable names beginning with a lowercase letter are local variables; those beginning with a capital letter are constants; those beginning with $ are global; and those beginning with @ are instance variables. Other scope variables exist, along with several special global variables. Ruby allows only single inheritance. This may sound limiting at first, but it means that naming clashes and other issues stemming from multiple inheritance are avoided altogether. Ruby does provide a mechanism for overcoming the perceived difficulties single inheritance may cause, called "mixing in," where methods from other classes may be included into a subclass that is then inherited. Other features that help define Ruby as a language include garbage collection, method overloading, and dynamic typing and definitions. Let's walk through the sample script for a look at Ruby's syntax. Sample scriptThis script is run as an interactive session in a DOS or UNIX shell. I've outlined some of the more basic constructs of Ruby, but a wealth of user-defined loops and other interesting features is available. First, we begin with a simple prompt. Notice that Ruby has no line termination syntax. Code: Ruby
Code: Ruby
Code: Ruby
Code: Ruby
Code: Ruby
Code: Ruby
Code: Ruby
Code: Ruby
Code: Ruby
Code: Ruby
end Where to get Ruby
Rare gemIn the forward to the book The Ruby Way, Matsumoto states that in developing Ruby, he "followed the Principle of Least Surprise" to create a scripting language that is "human-oriented" and that feels natural to developers. Indeed, Ruby provides a straightforward, logical methodology for quickly achieving the solution you seek. |
Re: Introduction To Ruby
Hi
Nice article and i need this. Is ruby better than PHP? Or they are different with each other. thanks |
Re: Introduction To Ruby
I think its between php and perl .... can you please provide me an example where I should use ruby instead of php
|
Re: Introduction To Ruby
Hello friends.............
Great. Nice Article.Thanks for sharing this information.I will try.This article is very useful. Thanks alot.:nonod: |
Re: Introduction To Ruby
Good description of your article.
Such Ruby is a useful tool for development and creation of prototypes. Your suggestion is really useful and better way to explain with example. |
Re: Introduction To Ruby
Thanks for your detailed post! Good luck to you!
|
| All times are GMT +5.5. The time now is 20:24. |