1. Computing

Ruby: Most Popular Articles

These articles are the most popular over the last month.
Command-line Arguments in Ruby
Use command-line arguments to pass parameters to your Ruby scripts from the command line.
Running Ruby Scripts
Learn how to use the command line interface on Windows, Linux and OS X to run rb files and use the interactive Ruby program.
Hashes
This article explains and teaches how to use a associative arrays (hashes) as a way to store multiple variables in one data structure.
Comments
Use comments to annotate your Ruby code.
Is the 'Require' Method Overlooked in Ruby?
The 'require' method is the reusable code mechanism in Ruby. It allows you to import other source files into your programs.
Environment Variables
Using environment variables in Ruby.
How to Create Arrays in Ruby
This article explains and teaches how to use a arrays as a way to store multiple variables in one data structure.
Install Ruby on Linux
How to install Ruby on the Linux operating system.
Loops the "Ruby Way"
Loops, including while and include loops, are one of the most commonly used constructs in computer programs.
NameError: uninitialized constant Object::Somet...
Problem: You encounter an error reading NameError: uninitialized constant Something or NameError: uninitialized constant Object::Something (with various class names in place of Something).
String Substitution in Ruby
Splitting a string is only one way to manipulate string data. You can also make substitutions to replace
The JSON Gem
It's easy to jump into parsing and generating JSON in Ruby with the json gem. It provides an API for parsing JSON from text as well as generating JSON text from arbitrary Ruby objects. It's easily the most used JSON library in Ruby.
Using the 'split' Method
String manipulation using the split method in Ruby. Split strings into a list of substrings.
NameError: undefined local variable or method...
Problem: You encounter an error reading NameError: undefined local variable or method `a' for # or NameError: undefined local variable or method `a' for main:Object (with various identifiers in place of 'a').
Install Ruby on Windows
How to install the Ruby interpreter on the Windows operating system.
10 Great Resources to Learn Ruby for Free
Sometimes the old adage rings true: the best things in life are free. If you've wanted to learn a little Ruby, but haven't been able to fit a programming course into your budget, don't worry. There are a number of places on the Web to begin your learning, without sacrificing money or quality.
Using Glob with Directories
In the previous article in this series, we discussed the basics of the Dir class. Particularly useful was the Dir.foreach method for iterating over all files in a directory. However, this only goes so far. What if you want to iterate over only some files (for example, just XML files) in a directory?
Install Ruby on OS X
How to install Ruby on Apple OS X
Using the Logger Library--How to Write Log...
How to use the logger library to create and write to log files in Ruby.
Using OptionParser to Parse Commands in Ruby
Using OptionParser to parse command line options is a preferable alternative to GetoptLong or looking through ARGV manually. But how do you use it?
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.
How to Install Ruby
How to install the Ruby interpreter on Windows, Linux and OS X.
What is Ruby?
What type of language is the Ruby programming language?
How to Use Loops in Ruby--While, Until, Each...
Loops, including while and include loops, are one of the most commonly used constructs in computer programs.
OptionParser--Parsing Command-line Options the...
Ruby comes equipped with a powerful and flexible tool to parse command-line options, OptionParser. The class is an alternative to GetoptLong for analyzing command line options.
The Interactive Ruby Prompt
Learn how to use the command line interface on Windows, Linux and OS X to run Ruby scripts and use the interactive Ruby program.
Installing RVM on Linux
Installing the Ruby Version Manager (RVM) on Linux
Using Strings
Using and manipulating strings and substrings in Ruby.
The Ternary (or "Conditional") Operator
The ternary (or "conditional") operator will evaluate an expression and return one value if it's true,
Making Deep Copies in Ruby
It's often necessary to make a copy of a value in Ruby. While this may seem simple, and it is for simple objects, as soon as you have to make a copy of a data structure with multiple array or hashes on the same object, you will quickly find there are many pitfalls.
Using RVM Gemsets
One of the most powerful, useful and often overlooked features of RVM is the gemset. A gemset is a separate gem directory, so the gems in one gemset don't conflict with the gems in another gemset.
The Case Statement
The case statement is a control structure that is usually quite limited in other programming langauges. However, it's quite powerful and flexible in Ruby.
Riding Shotgun with Sinatra
Now that you can write controller logic and views and Haml, you can start putting together some more complex application. There's one very annoying thing though: Sinatra does not reload its code whenever you make a change. If you make a change, you have to stop and restart the server. This is just an extra step and generally an annoyance. This where shotgun comes in.
Using Pipe Characters
Learn how to use the command line interface on Windows, Linux and OS X to run Ruby scripts and use the interactive Ruby program.
Splitting Strings
Unless user input is a single word or number, that input will need to be split, or turned into a list of strings or numbers.
Net::SSH--The SSH (Secure Shell) Protocol
Net::SSH is a way for Ruby to interact with SSH (Secure Shell) protocol. It relies on the OpenSSL library for encryption.
25 Gem Commands for RubyGems
The gem command is one of the most used Ruby-related commands. This article shows 25 Gem Commands and their functions.
Installing Gems from Git
How to install gems from git repositories.
Installing a Ruby Development Environment on...
In the past, the Ruby “One-Click Installer” was the primary choice for installing Ruby on Windows. However, the One-Click Installer fell into disrepair and was eventually abandoned. Something new was needed, and thus, RubyInstaller was born.
Generating Random Numbers in Ruby
It's often useful in games, simulation and unit testing to generate random numbers, Ruby provides easy access to a pseudo-random number generator.
What's New in Ruby 1.9.1? -The Lambda Operator
Among the new features in release of Ruby 1.9.1 is the Lambda operator, a shortcut used to make nameless methods. Learn how to use this feature introduced in Ruby 1.9.1.
Using Attributes
There are two basic things you can do with an object: call a method on it and access an attribute. Ruby doesn't make a distinction between these things, but it does give you some tools to make some methods act like attributes.
Step 3: Authentication with Devise
Before we get too invested in our blog, we need to set up some authentication. Since the goal is to allow users to register and post comments, we'll also need a way to differentiate between normal users and bloggers. We'll be using the popular and capable Devise gem to handle authentication for us.
Adding Files to a Repository
How to add files to a Git repository.
Installing Git on Windows
Installing command line tools such a Git on Windows is often difficult. Not only do you have to find a Windows port or attempt to compile the tool yourself from C source code, you also have to deal with the Windows command line. The Windows command line is, to say the least, a little lacking. Windows users are in luck here though, the MSysGit project solves both these problems.
CSV Example: Parsing CSV
A crash course on what CSV is, what it is used for and how it is parsed. A method for parsing CSV files using only Ruby's built-in string methods is presented and discussed.
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.
Hello, Sinatra! Using Sinatra in Ruby
How to get started in Sinatra, including how to use actions, parameters, ERB and views.
What is Cloud Computing?
What is cloud computing? Interviews with industry experts help us define cloud computing, software as service, platform as service and more.
Using Rack
In the previous article, you learned what Rack is. Now, it’s time to start using Rack and serve up some pages.
Base64 in Ruby
Base64 is a way to represent any data as ASCII data. Ruby provides a few handy functions to encode and decode Base64.
Optional Method Parameters with Hashes
Using hashes to simulate optional named parameters in methods.
Adding and Installing Gems from the Ruby Gems...
Learn to search the Ruby Gems repository to find gems to add and install to your library.
protect_from_forgery
A feature in Rails that protects against Cross-Site Request Forgery (CSRF) attacks.
Eval: Running Code on the Fly
Most non-compiled languages have some kind of eval function, which will take a string and execute it as code.
How to Use the Twitter Gem for Ruby
Using the Twitter RubyGem, making API requests to Twitter is even easier than using the twitter method.
How Does Ruby Compare to Python?
How do Ruby and Python compare in terms of features, form and function?
How to Use and Create Blocks in Ruby
How to use blocks in Ruby.
Can I add empty directories to Git repositories?
Can I add empty directories to Git repositories?
The ‘exec’ Method
There are several ways to run other programs in Ruby. There is the system> method, backticks, etc. However, they all spawn new processes. If there is nothing left for your Ruby program to do, it has to sit there wasting memory until the launched program finishes. The exec> method fixes this.
Instance Variables
Instance variables are some of the most common and important variables types in Ruby. They begin with the at sign (@) and allow objects to track their internal state.
Serialization in Ruby: Marshal
Serializing an object is to convert an object to a byte stream and either store that object for future loading, or sending to another program to be loaded there. There are several common ways to serialize objects in Ruby. The Marshal module is used less often than the other methods, but it's included in the standard library.
undefined method `to_sym' for nil:NilClass
Problem: Seemlingly at random, you've encountered the error undefined method `to_sym' for nil:NilClass, or a similar error message for any method name other than to_sym.
Constant Variables
The speed of light (unless you've read the recent news ) is the constant and unbreakable speed limit
extconf.rb:1:in `require': no such file to load...
Problem: You're trying to install a gem and you encounter an error reading no such file to load -- mkmf. This doesn't always occur, only when you're trying to install gems with native C code that must be compiled.
Instantiation and the Initialize Method
Ruby objects are instantiated using the Class.new method, and initialize using their own initialize methods.
What is Sinatra?
Sinatra is a web framework. Simply put, it's a library that allows you to write web applications with a minimum of red tape.
Graphical User Interfaces: Installing Tk
Directions of how to install the Tk GUI and its Ruby bindings on Windows, Linux and Mac OS X.
What's New in Ruby 2.0.0?
The Ruby 2.0.0 preview 1 release was just pushed out, what can you expect in this shiny new version?
Constants in Ruby
Like just about every programming language every conceived, Ruby supports constants. A constant is a variable whose value cannot be changed. However, in Ruby, this has some caveats.
Using Git With Ruby on Rails
You don't have to use version control, but you should be. In the past, version control software has been large, clunky, required servers and really was only used when working in groups. But with Git, it's so easy that you really have no excuse, you should be using version control.
Getting Started with Bundler
The basics of using Bundler are very trivial, you can be up and running in just a few minutes.
What is Ruby on Rails?
What is the Ruby on Rails web framework?
RVM and 'sudo'
RVM is great. However, there may be times where you must run Ruby scripts with RVM as root (or another user) via sudo.
Installing Git on Linux
There are multiple ways of installing Git on Linux. Depending on which Linux distribution you're using and whether it provides binary packages for Git, you can either install a binary package or install from source.
Named Regexp Groups
Ruby 1.9 introduces the concept of a named capture group. These named groups can be defined at the beginning of a regexp statement using a trick that tells for the regexp engine to look for exactly 0 instances of the group. Later, the group can be recalled using the \g element, followed by the name of the group. You can think of named capture groups as subroutines inside of a regular expression.
Installing Ruby on Rails on OS X
While Apple does include both Ruby and Ruby on Rails by default with OS X, you'll need to install newer versions. This is a bit of a process, but thankfully you'll only need to get through this just once.
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.
NoSQL and Document Oriented Databases
Chances are, you've spent your entire database life with relational databases. Data gets organized into columns, and stored in rows. You manipulate data with SQL (Structured Query Language) and there's really no other way to do it. There are competing SQL servers out there (MySQL, SQLite, etc), but they all more or less operate in the same way. But there's much more out there than SQL databases, especially with all the new software in the past few years.
Cryptographic Hashes in Ruby
Generating cryptographic hashes in Ruby is quite easy. Ruby provides both a built in method and gives access to OpenSSL's hashing algorithms in most installations.
String Literals
The basics of strings, string interpolation, single and double quotes, escape sequences and alternate string literal syntaxes.
What is RVM?
RVM is the Ruby Version Manager. It allows you to install and manage several different versions and implementations of Ruby on one computer, including the ability to manage different sets of RubyGems one each.
Serialization in Ruby: YAML
YAML (YAML Ain't Markup Language) is perhaps the most common form of serialization in Ruby applications. It's used for configuration files in Rails and other projects, and is nearly ubiquitous. It also has distinct advantages over marshal, and is usually preferred.
Using Haml with Sinatra
How to use Haml to create Sinatra views and layouts.
Making a Text Adventure Game in Ruby
Text adventure games were a very popular game genre on minicomputers and microcomputers from the 1970's through the 1990's. This article series will take you through each step of making a text adventure game in Ruby.
Block Parameters and Yielding
Block parameters allow you to pass small anonymous methods to a method call. It's so common an idiom
What is Rack?
There’s a lot of talk about Rack , but unless you’re a framework author yourself, you rarely see it. So what is Rack? And why, as an application developer, should you care about it?
Using the Enumerable Module
By using the Enumerable module, you can make any of your classes act like Ruby standard collections. All you need to do is implement the 'each' method.
Class Variables
Class variables in Ruby are more or less as you'd expect form an object oriented language. However, Ruby throws you a curveball you can use to your advantage.
Ruby on Rails Tutorial - Starting the Blog
Generating a Rails project from which to build an application.
Block Variable Scope in Ruby 1.9.x
The release of Ruby 1.9.1 brings new features to be learned,among them are the changes in block variable scope. Learn the new syntax for block variable scope introduced in Ruby 1.9.1.
Boolean Operators
While simple boolean expressions will get you pretty far, you'll soon find yourself wanting to act on more than one condition. For that you'll need boolean operators.
Running the Ruby Profiler
Running the Ruby profiler to determine which methods are most expensive and which need to be optimized.
5 Tips for Using Twitter With Ruby
Twitter provides programmers with an excellent API, which is why so many Twitter interfaces exist for tweeting, following updates, following friends and thread-sorting. Writing Twitter clients in Ruby is a breeze!
A Quick Introduction to DataMapper
DataMapper is a "Object/Relational Mapper" or ORM. In other words, it maps Ruby objects to database records
Worked Example: Tabular Data
Much is made of the two base data structures in Ruby: the Array and the Hash. However, it's also quite easy to use two dimensional arrays in Ruby.
Installing Ruby on Snow Leopard with RVM
OS X has pretty easy access to a GCC development environment installed with XCode (an IDE and development
Mapping Arrays
Iterating over Arrays isn't the only trick up Ruby's sleeve. Mapping Arrays (and other collections, any Enumerable collection will work) is a very powerful feature.
Rapid Game Prototyping in Ruby
Myth: Ruby is unsuitable for game development. It's much too slow, there are no good libraries and it's too hard to deploy your games written in Ruby.
How Does Ruby Compare to the Java Programming...
What features do Ruby and the Java programming language share? How are they alike and how are they different?
Visual Tutorial: Installing Rubygame on Windows
A visual tutorial with screenshots showing how to install the Rubygame library on Windows, including installing all needed DLL files.
Boolean Expressions
A boolean expression is an expression traditionally used in a conditional or loop construct that decide
Structure of a JSON Document
JSON is a data serialization format for communicating between applications. It's a text format that features a lightweight syntax and closely mirrors the common data structures in modern programming languages.
RubyMine 5.0
I've always been a Vim person. Just give me a good solid editor and I'll take it from there. But I decided to give RubyMine a good honest try, and here's what I think about it.
Deploying Applications with Bundler
This article was written for Bundler version 1.0. If you are using a later version of Bundler, the commands
Automatically Following Followers on Twitter
Since the Twitter API makes it easy to do anything you can do on the website, writing a Ruby script to automatically follow followers is very simple.
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?
The Link Class
The Link class is what you use to navigate from one page to another. The Link class itself is quite small, there just isn't much to a link. It doesn't have many methods, the click method being the most used by far.
How to Display Your Ruby Version in Your Bash...
With RVM installed on your system, it's easy to have many versions of Ruby installed. And, especially if you switch between them often, it's easy to forget which Bash command prompt is using which Ruby version. You can solve this by putting your Ruby version in your Bash prompt.
Retrieving a Tagged Release
Once you have releases tagged in the repository, it will be useful to retrieve tagged releases. For example, I want to see if a bug was present in version 0.3, so I'll want to retrieve version 0.3 and run it. Git, of course, makes this easy.
Net:SSH--Executing Programs with Net::SSH
Running programs with Net::SSH is simple enough. The Session object gives you two convenient methods with which to accomplish this task.
Package Manager
A package manager is software on a Linux system that manages the other software installed on the system.
What is Bundler?
Bundler is a gem dependency manager for Ruby.
Net:SSH--Transferring Files with Net::SCP
SSH is not just for running commands, it's a general conduit for encrypted communications between two hosts. One common use for SSH is to transfer files using the SCP protocol over SSH. You can use SCP in your Ruby programs with the Net::SCP library, which is a supplement to Net::SSH.
Finding Links
Most likely, you'll be wanting to find links and click on them. There are three methods that help you
How Can I Store Key/Value Pairs in Ruby?
Storing key/value pairs in Ruby doesn't always need to be accomplished by using a hash. You can also use the Struct and OpenStruct classes.
Check Email With Ruby
Learn to use Ruby's pre-installed POP3 libraries to check your email.
How Can I Benchmark Code in Ruby?
Benchmarking measures the time it takes to execute code and compares it to other code that accomplishes the same task. This is useful to see which is faster, and gives you the opportunity to use the faster code in your program.
Data Visualization
We've been organizing our game data in a tree, but a tree is kind of hard to visualize. Single objects and arrays you can simply puts to the terminal, but trees are a bit more difficult. Two methods are presented, one that prints the tree to the terminal and another that generates an image.
Iterating Over Strings
It's not a very common thing in Ruby. You have more sophisticated string tools (such as split or scan), but there are times when you'd want to iterate over the characters in a string. Unicode complicates this matter, but Ruby makes it simple.
Using Temporary Files
There are many hidden pitfalls when using temporary files. Ruby's Tempfile class solves many of these.
Getting Information About a File in Ruby Using...
Sometimes blindly opening files just won't cut it, sometimes you need to know more information about a file before opening it.
Sinatra URL Matching
How do do various types of URL matching in Sinatra.
Installing Ruby on Rails on Windows
Installing Ruby, Rails and the few other things you'll need way always a pain on Windows. It's just not a very friendly environment for the task. But fear not, the guys at EngineYard have made RailsInstaller, and this task is braindead simple and will be done in minutes.
Global Variables
Global variables are not often used in Ruby, however, you should at least understand their usage should you ever encounter them.
Your First Controller
Now that you have a new Rails project, you're probably at a loss of where to go. Let's start by generating a new controller.
Overloading Operators
What does a + b mean? That all depends on what 'a' is. Ruby allows you to define a number of arithmetic operators and they're called on the left-hand side of any such expression.
Rails Blog Tutorial - Allowing Comments
Part four of the Ruby on Rails blog tutorial shows you how to create a comments table to allow users to comment on your blog posts.
The Complete Code
This article will create a rolodex application that can be used to keep track of contact information. The total line count is about 130 lines, split about half and half with code and views.
Creating Database-driven Apps with Sinatra
This article will create a rolodex application that can be used to keep track of contact information. The total line count is about 130 lines, split about half and half with code and views.
Working with Directories
Learning how to work with files is one of the first things new Ruby programmers learn. However, how to work with directories of files is something that's often skipped or only lightly touched upon. Ruby does have some powerful mechanisms for working with directories though.
Ruby Best Practices--Making Quick Exceptions
Knowing how to make quick exceptions to catch and tell the difference between several conditions is a Ruby best practice you can't afford not to know.
Creating Hashes from Arrays
How do you create hashes from tabular data? There are a few ways, but there's a way built into Ruby that fits onto a single line.
5 Must Know Features of the Ruby Language
If you're going to program in the Ruby language, there are some basic features you absolutely must know. Here are the Top 5.
Special Characters & Escape Sequences
Aside from the basic regular expression operators such as groupings and quantifiers, there are some other special characters and escape sequences (backslash followed by a character) that can help you out when you're working with Ruby.
Creating and Distributing Gems with Bundler
Creating Ruby gems has always been a bit of a pain. When you get right down to it, it's not a hard thing to do, but it's easy to forget how if you don't do it often enough. There are quite a few gems to help you write other gems, but if you're using Rails 3, there's already a gem on your system that does this: Bundler.
Loops
Ruby has a the usual and expect loops, as well as a number of loops specific to Ruby. It even has a way to define you own types of loops.
Conditional Statements
Conditional statements are what makes computer programs tick. Without conditional statements, all computer programs would follow the same path from beginning to end.
Step 2: Integrating a Wordpress Theme
The scaffold generator gave us something rather spartan, let's spruce this up by adapting a Wordpress theme to work with our shiny new blog.
Debugging Ruby
Debugging Ruby programs using the Ruby debugger.
Unit Testing with MiniTest
While the earlier versions had the perfectly fine unit testing framework Test::Unit built right in, Ruby 1.9.x and up come with MiniTest as part of the standard library.
Ruby on Rails 3 Tutorial: Learn Rails by Example
Ruby on Rails 3 Tutorial: Learn Rails by Example by Michael Hartl is a hands on introduction to not only Ruby on Rails but all the related software and services many Rails developers use such as Git, Github, Heroku and RSpec. There are no long-winded discussions on theory or REST or MVC, each and every part of every chapter is a hands on exercise in building a Rails application. This book is recommended for anyone who prefers a hands on approach to learning.
Methods
Methods are very important in Ruby. You have probably used them before, but have you thought about how to really define them?
Are You Sure You Want to Exit? and Other Dialog...
We've all had to respond to that ubiquitous question: Are You Sure You Want to Exit? Ever wondered what was behind creating them? Shoes gives you 5 different dialog methods to choose from.
Using rails.vim
Editing Rails projects in Vim effectively.
Making Forms and Views
So far, we've discussed how to use Sinatra in general, how to handle and route requests, and how to build views using Haml. Before we take the plunge into using data storage with Sinatra, let's put what we've discussed so far into practice. This article explains how to use Sinatra to provide a web interface for a gem.
Overlooking Input and Output? Using the Input /...
Input and output methods are often overlooked by many Ruby programmers. How often have you used the <b>gets</b> and <b>puts</b> methods without giving them a second glance? Learn all the features of these methods to better put them to use in your code.
Dealing With Ruby Vulnerabilities: Enable...
Knowing what vulnerabilities exist in your Ruby code is only half the battle. You also need to know how to counteract them. Begin by enabling forgery protection.
Making Digraphs in Ruby
Digraphs are extremely useful for hierarchical data visualization. However, they're not very easy to generate yourself. This is where Graphviz and the Graph gem come in.
How to Send Email with Ruby
How to send email with Ruby on Rails using SMTP.

Discuss in my forum

©2013 About.com. All rights reserved.