1. Technology
Send to a Friend via Email

Beginning Ruby

If you're just getting to know Ruby, these articles will tell you what you need to know to get started. From a basic explanation of the programming language to comparison to other programming languages to descriptions of descriptions of Ruby's basic features, you'll get to know Ruby.
  1. Collections: Arrays, Hashes and Enumerable (3)
  2. Comparisons: Ruby Vs. The World (5)
  3. Control Structures (13)
  4. Files and Directories (5)
  5. New Features in Ruby 2.1.0 (3)
  6. New in Ruby 1.9.x (13)
  7. Object Oriented Programming (12)
  8. Ruby's Basic Features (20)
  9. Strings (16)
  10. Tutorials on the Web (2)
  11. Variables (11)

Must-Read Ruby Links
This is a collection of must-read Ruby links (and one must-watch). Every single one of them is an information and understanding goldmine.

What is Ruby?
What is Ruby really? Whether you're new to Ruby or new to programming, this article will explain what Ruby is as buzzword-free as possible.

Array Quick Reference
The Array class has over 90 methods, plus others inherited or brought in from other modules. This article cuts through the noise and just tells you what you need to know about Arrays.

IO Quick Reference
You use IO methods all the time: gets and puts. However, there are more options available to you, should you need them. As there are many, many methods of the IO class, as well as the file and socket classes and subclass them, this should cut through the noise and tell you what you need to know.

Using PLEAC To Get Up To Speed Quickly
PLEAC is most useful when you think to yourself "How do I do XYZ in Ruby again?" You might just be forgetting the exact syntax of a language construct or the name of a method, and PLEAC will bring you up to speed quickly.

String Quick Reference
The Ruby String class has well over 100 methods, this is a difficult minefield to navigate when you're just starting out. This article cuts through all the noise and just tells you what you need to know to start using Strings in Ruby.

Hash Quick Reference
As Ruby releases move forward, more and more methods get added to the base classes. This article cuts through all the noise and just tells you what you need to know to be able to work with hashes.

Mixin Modules
Mixins are one of Ruby's defining features, but often one of the most difficult to understand for those new to Ruby. They're not difficult to understand, but they're not something most programmers have encountered before as most languages don't have mixins.

What's New in Ruby 2.0.0?
The Ruby 2.0.0 release just dropped. This is no minor update (though it's not game-changing either), but there's a whole host of new features you should know about!

Bignum Quick Reference
The Bignum class is something you may have encountered before. While most languages only use native integers and give an error if you try to produce a number higher than a few billion, Ruby can handle numbers of arbitrary size using the Bignum class.

How Do You Comment Your Ruby Code?
Commenting Ruby code is a good way to leave notes and annotations for other programmers, but it's not always easy to decipher. How do you comment your code?

Capturing the Return Value of an External Program
Ruby makes it easy to run external programs and capture their output. Using the built-in "backtick" operator is as easy as running these programs from the command line. However, it's not obvious how to capture the return value of these programs.

Practical Ruby
From installation to using RubyGems to simple tasks and tutorials, this page will give Ruby on Rails programmers a few ways to begin using their programming chops.

Quick Tip: Last Result in IRB
There's a really quick way to get the result of the last expression evaluated in IRB.

5 Must Know Features of Ruby
If you're going to program in Ruby, there are some basic features you absolutely must know. Here are the Top 5.

Keyword Arguments
Until Ruby 2.0, Ruby did not have true keyword arguments. You could simulate them using a hash, but that was a bit of a hack. Now, in Ruby 2.0, you can use true keyword arguments.

A Beginner's Guide to Ruby
What type of language is the Ruby programming language?

Block Parameters and Yielding
Block parameters allow you to pass small anonymous methods to a method call. It's so common an idiom in Ruby that it's replaced "for" loops as preferred idiom for iteration. When was the last time you saw a for keyword in Ruby? You rarely see it, Rubyists use the each method, possibly on a Range object if a series of numbers is needed.

Installing jRuby With RVM on OS X
As with most flavors of Ruby, the easiest, cleanest and least painful way to install jRuby is with RVM, the Ruby Version Manager. And although jRuby is different than MRI, the official Ruby interpreter, it can be installed just as easily, arguably easier.

Exception Quick Reference
Exceptions represent not only errors, but any exceptional condition where the program simply cannot continue. And exceptions, like everything else, are objects in Ruby.

Quick Reference: Logger
The Logger class in the standard library is a dead-simple interface to writing log files.

TrueClass, FalseClass and NilClass Quick Reference
What is true in Ruby? What is false in Ruby? This articles define's Ruby's concept of "truthiness" and explores the objects that represent truth in Ruby.

The Ruby Homepage
Homepage of the Ruby programming language. Download Ruby, view documentation and stay up to date with Ruby developments.

Interacting with External Programs
You’ve learned how to launch external programs using both system or backticks and using the exec method. These are both fine, but only on one condition: the program launched doesn’t require any input.

The Zen of Learning Ruby
Learning Ruby isn't often thought of as a Zen exercise, but that's exactly how the guys at EdgeCase saw it. Thus RubyKoans was born.

Quick Tip: Install Gems Faster
Some larger projects, especially Ruby on Rails, come with quite a bit of documentation. This is good, documentation is good, but the code that processes this documentation (RDoc) into HTML and ri format is not exactly speedy. On slower computers, or with larger projects, the time this takes becomes and annoyance.

The Magic of Symbol#to_proc
How do you convert a Symbol to a Proc? What does it even mean to do that? The Symbol#to_proc method is a shortcut or convenience method used in a variety of places in methods that accept blocks.

Command-line Arguments
Use command-line arguments to pass parameters to your Ruby scripts from the command line.

Comments
Use comments to annotate your Ruby code.

Aliasing
Aliasing is a powerful Ruby feature that allows more than one method to be referred to by multiple names. This can be used to give a programmer more expressive options or to create copies of a method, allowing you to change the behavior of a class.

Using the 'require' Method
The 'require' method is the reusable code mechanism in Ruby. It allows you to import other source files into your programs.

Exceptions
Exceptions are used to handle things the unexpected things that might go wrong with your Ruby code. This article addresses what Exceptions are and how they can be used.

How to Install Ruby
How to install the Ruby interpreter on Windows, Linux and OS X.

Using the Command Line
How to use the command line interface on Windows, Linux and OS X to run Ruby scripts and use the interactive Ruby program.

Using the Command Line
How to use the command line interface on Windows, Linux and OS X to run Ruby scripts and use the interactive Ruby program.

Building Hashes
A hash is an associative array. Instead of using numerical indexes, any object (but typically symbols) can be used. They can be both a fast way to retrieve an object based on a key, and a convenient key/value store. There's no doubt, hashes are one of the most used types in Ruby.

Why JRuby?
As a Rubyist you probably know and love the official Ruby implementation. It's very stable and capable, so why should you use JRuby?

Getting Information About a File in Ruby Using File::Stat
How large is a file? Is it a symbolic link? The File::Stat class can tell you information about a file.

Worked Example: Number Guessing Game
A number guessing game is written an examined. This is perhaps the simplest game that can be written, and is a classic newbie program for any programming language.

Worked Example: Tabular Data
There are two main data structures in Ruby: the Array and the Hash. However, it's also quite easy to make more complex data structures such as two dimensional arrays.

Ruby-Doc.org
Archive of Ruby documentation from across the world wide web.

Programming Ruby
First edition of the book "Programming Ruby: The Pragmatic Programmer's Guide" for free online.

Ruby Wikipedia Entry
General information about Ruby and the history of Ruby.

JRuby
An alternative implementation or Ruby written in Java and officially supported by Sun Microsystems.

The Forgotten Keyword: The 'for' Loop
In most imperative languages, one of the primary loops is the 'for' loop. You may have even learned it early on in your Ruby career, but promptly forgotten about it. It just isn't idiomatic Ruby, you'll almost never see it in production code, but it does have some minor uses.

The Ternary (or "Conditional") Operator
The ternary (or "conditional") operator will evaluate an expression and return one value if it's true, and another value if it's false. It's a kind of short-hand, compact if statement. It has its uses, but it's also a bit controversial.

Predefined by Ruby
Ruby defines a number of built in global variables you may find you need at one point.

Conditional Assignments
The shortcut rule (which says in a || b if a is true then don't evaluate b) can be used for efficient conditional assignment.

Effective Debug Messages
Using simple techniques to improve your debug messages.

You can opt-out at any time. Please refer to our privacy policy for contact information.

©2014 About.com. All rights reserved.