LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to Linux Subscribe to Newsletters

An Introduction to Ruby

by Colin Steele
10/25/2001

Ruby is an object-oriented scripting language that combines the object-oriented programming (OOP) power of Smalltalk with the utility of Perl and the power of Python.

I can already hear you grumbling, "Oh, great, another language." Why should you care? You're already up to your elbows in technologies to learn, right? Well, call your significant other and tell him or her you're going to be late tonight. And go get another Jolt. You're going to be hooked on Ruby for the simple reason that Ruby makes programming fun again (and that's what really counts).

This article introduces Ruby by examining the high-level properties of the language as well as some important features that distinguish it from other languages. We'll compare Ruby with Perl and Python. Along the way, I'll provide my personal take on Ruby, and why I think you'll love it as much as I do.

Traits That Recommend Ruby

Looking down on Ruby from 50,000 feet, we see it has several qualities that recommend it as the next language you should learn, including its consistency and elegance, OOP features, ease of use, extensibility, and its applicability to rapid development.

But what exactly is Ruby? It's a weakly typed, interpreted, cross-platform language implemented in C, written from the ground up to be object-oriented. Ruby's been around since 1995, and has its largest following in Japan, the home of Ruby's author, Yukihiro Matsumoto, a.k.a. "Matz." Although Ruby is more popular in Japan than Python, you may not have heard much about it, yet. Or, if you have, you may have heard that it's a "better Perl than Perl."


O'Reilly & Associates will release Ruby in a Nutshell in November 2001. Beta Sample Chapter 4, Standard Library Reference, is free online.


I think there's a large measure of truth in that statement. Ruby somehow manages to combine some of the best features of Smalltalk, C, Perl, and Python in a package so elegant and natural that I found myself hooked after just one day.

Some of Ruby's strongest traits are:

  • Consistency. This is perhaps the single most important trait of Ruby. Like C, Ruby is a small language. It's a simple language, and Matz has made sure that a small set of rules govern its design. The result is Ruby stays out of your way; you don't have to build scaffolding to get it to actually work on the problem at hand.

  • Elegantly object oriented. Ruby fully supports object-oriented programming, with a from-the-ground-up, internally consistent and straightforward object model. Ruby has all the features you'd expect from an OOPL, including classes, methods, (single) inheritance, polymorphism, class methods, exceptions, and more. These features are designed from the beginning, not glued-on, which means Ruby doesn't have the little inconsistencies and gotchas you'll find elsewhere.

    For example, remember when you were learning C++ and the difference between pointer-to-function and pointer-to-member-function bit you on the butt? Or in Perl and Python, where the object (or reference, or string) is passed to your method as the first argument? Or the lack of access controls in Perl. Or.... Well, you get the idea.

  • Easy to use. Ruby's consistency and its object model make it easy to use. The syntax is simple, clean, and readable, with an expressiveness that gives your code a natural flow. Specific features of the language, such as the ability to pass code blocks on method invocations, make Ruby source wonderfully transparent. There's little of the "line noise" you find in other languages, and although there's also none of the bondage-and-discipline nature you'll find in other languages, Ruby seems to promote a sparse, readable, succinct coding style.

  • Easy to extend. Using its C-interface extension API, you can create interfaces from Ruby code to existing third-party commercial or noncommercial libraries, or selectively implement methods or classes in a lower-level programming language to improve performance.

  • Perfect for rapid development. Finally, because Ruby is an interpreted language, it is ideally suited to rapid application development. Write your code, run it, debug it, and run the modified code again--fast, simple, and fun. This low-torque, high-revolution implementation style lets you flow more easily from conception to incarnation as you code. The result can be a surprising increase in your productivity. Although Ruby can be used for large-scale, long-term projects, I now count it as my favorite language for prototyping and spike-solution development.

These aspects of Ruby arise from the design of the language, its purpose, and its heritage. But aside from these more abstract positive qualities, there are several specific language features that you'll want to explore in Ruby. These include code blocks/closures, iterators, variable scoping by name, and its uniform object treatment.

Pages: 1, 2

Next Pagearrow




Tagged Articles

Post to del.icio.us

This article has been tagged:

ruby

Articles that share the tag ruby:

Rolling with Ruby on Rails (2837 tags)

Ajax on Rails (525 tags)

Rolling with Ruby on Rails, Part 2 (241 tags)

The Builders of Basecamp (54 tags)

Technologies to Watch: A Look at Four That May Challenge Java’s Development Dominance (47 tags)

View All

programming

Articles that share the tag programming:

Rolling with Ruby on Rails (1374 tags)

Very Dynamic Web Interfaces (279 tags)

Ajax on Rails (231 tags)

Understanding MVC in PHP (202 tags)

A Simpler Ajax Path (186 tags)

View All

introduction

Articles that share the tag introduction:

Demystifying LDAP (11 tags)

A Beginner's Introduction to Perl 5.10 (7 tags)

An Introduction to Ruby (6 tags)

What Is the X Window System (5 tags)

An Introduction to FOAF (2 tags)

View All

oreilly

Articles that share the tag oreilly:

What Is Web 2.0 (2327 tags)

A Simpler Ajax Path (19 tags)

Ajax on Rails (17 tags)

Wireless Mesh Networking (15 tags)

Understanding MVC in PHP (12 tags)

View All

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com