Ruby: Most Popular Articles
Is Ruby a good first language to learn? Everyone has to start somewhere, and is Ruby an appropriate place to start if you're looking to take the plunge and learn a programming language?
Problem: You encounter an error reading NameError: uninitialized constant Something or NameError: uninitialized constant Object::Something (with various class names in place of Something).
This article explains and teaches how to use a associative arrays (hashes) as a way to store multiple variables in one data structure.
Learn how to use the command line interface on Windows, Linux and OS X to run rb files and use the interactive Ruby program. Page 2.
This article explains and teaches how to use a arrays as a way to store multiple variables in one data structure.
Use command-line arguments to pass parameters to your Ruby scripts from the command line.
The following is a list of articles that will show you how to write, style and deploy a URL shortener (like TinyURL) application in Ruby on Rails.
String manipulation using the split method in Ruby. Split strings into a list of substrings.
What type of language is the Ruby programming language?
Using environment variables in Ruby.
Loops, including while and include loops, are one of the most commonly used constructs in computer programs. Page 2.
The main loop is the heartbeat of any game, and is the first thing you need to learn to start making your own games.
Loading images from files and displaying them om the screen is the one of the most basic things you can do in game programming. Luckily, Rubygame makes this really simple.
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.
Use comments to annotate your Ruby code.
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.
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.
How to use the command line interface on Windows, Linux and OS X to run Ruby scripts and use the interactive Ruby program.
How to install Ruby on the Linux operating system.
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.
URL shortening is a useful feature for any Rails application. Making it easy for people to share links to your content is always a good thing.
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.
Problem: You encounter an error reading NameError: undefined local variable or method `a' for #
Using and manipulating strings and substrings in Ruby. Page 4.
class="no-js" itemscope itemtype="http://schema.org/Article" > itemprop="description" >Splitting a string
How to install the Ruby interpreter on Windows, Linux and OS X.
The 'require' method is the reusable code mechanism in Ruby. It allows you to import other source files into your programs.
Since we're talking about threads, we have to talk about mutexes. A Mutex is the only practical way to prevent race conditions (where more than one thread
How do Ruby and Python compare in terms of features, form and function?
Learn to search the Ruby Gems repository to find gems to add and install to your library.
class="no-js" itemscope itemtype="http://schema.org/Article" > itemprop="description" >Buttons primarily
Be notified of Twitter updates by IM, using this Ruby script. It's a pain to switch to a Web browser every you want to check your Twitter account. This script solves that by sending you an instant message (IM) using the Jabber protocol when there's something new to see on Twitter.
In the previous article in this series, we discussed the basics of the Dir class. Particularly useful was the Dir.for each 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?
Ruby objects are instantiated using the Class.new method, and initialize using their own initialize methods.
MiniTest provides an array of assertion methods that will make writing tests a breeze.
Using hashes to simulate optional named parameters in methods.
Iterating over arrays isn't the only trick up Ruby's sleeve. Having the ability to map arrays (and other enumerable collections) is a powerful feature.
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.
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.
Installing the Ruby Version Manager (RVM) on Linux. Page 2.
Using OptionParser to parse command line options is a preferable alternative to GetoptLong or looking through ARGV manually. But how do you use it?
Now that things are working correctly, it's time to make this actually look like a blog. We finally ditch the views generated by the scaffold generator, implement pagination and even RedCloth formatting.
class="no-js" itemscope itemtype="http://schema.org/Article" > itemprop="description" >The ternary (or
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.
A visual walkthrough on installing Ruby on Windows. Page 3.
How to use the logger library to create and write to log files in Ruby.
How to add files to a Git repository.
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.
Before we get too invested in our blog, we need to set up some authentication. We'll be using the popular and capable Devise gem to handle authentication.
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.
Ruby 2.1.0 includes a new small changes to numeric literals if you're working with rational or imaginary numbers, as well as a few changes to how Bignum works under the hood.
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.
What do you do when a new version of Rails comes out? Build a blog, of course. The blog is kind of the hello, world application of the web application world.
It's often useful in games, simulation and unit testing to generate random numbers, Ruby provides easy access to a pseudo-random number generator.
How to use the ruby-progressbar gem to display progress bars on the command line.
What features do Ruby and the Java programming language share? How are they alike and how are they different?
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.
Now that the core of the game is done, we take a few minutes and look at a few odds and ends. Among those, the code that spawns new tiles and the code that looks for the game over state.
What is cloud computing? Interviews with industry experts help us define cloud computing, software as service, platform as service and more.
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. Page 5.
OS X has pretty easy access to a GCC development environment installed with XCode (an IDE and development
The basics of using Bundler are very trivial, you can be up and running in just a few minutes.
New to Ruby? Or even to programming? Find out what Ruby really is (and isn't) and why you should (and shouldn't) use it.
How to use some of the most basic Tk widgets.
Net::SSH is a way for Ruby to interact with SSH (Secure Shell) protocol. It relies on the OpenSSL library for encryption.
class="no-js" itemscope itemtype="http://schema.org/Article" > itemprop="description" >Block parameters
Can I add empty directories to Git repositories?
The gem command is one of the most used Ruby-related commands. This article shows 25 Gem Commands and their functions.
How to install the Ruby interpreter on the Windows operating system.
A comparison of Ruby to other programming languages, including Perl, Java, Python and PHP.
Sinatra is a web framework. Simply put, it's a library that allows you to write web applications with a minimum of red tape.
Now that you have Linux up and running, and you have Ruby, time to add the two most essential parts of any Rubyist's toolbox: version control and a good editor. Page 3.
class="no-js" itemscope itemtype="http://schema.org/Article" > itemprop="description" >The speed of light
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.
If you're going to program in the Ruby language, there are some basic features you absolutely must know. Here are the Top 5.
How to use blocks in Ruby.
One of the most common tasks when dealing with arrays is to sort them. Luckily, Ruby makes this simple and flexible.
We'll use a two dimensional array to represent the 2048 game board, but how do we create a 2D array in Ruby?
The basics of strings, string interpolation, single and double quotes, escape sequences and alternate string literal syntaxes. Page 2.
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.
Now that Rails 4 is out, let's see what's new.
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.
How to install gems from git repositories.
Global variables are not often used in Ruby, however, you should at least understand their usage should you ever encounter them.
The following is a short collection of tips that are so obvious they've likely been staring you in the face for a very long time. Why haven't you been using them? You're likely stuck in a rut, doing things in a certain way without even realizing there is a slightly easier way.
Why are cloud computing and Ruby on Rails a good match? Let's hear what Hampton Catlin, author of HAML and Wikipedia's head Ruby/mobile architect has to say!
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.
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.
Base64 is a way to represent any data as ASCII data. Ruby provides a few handy functions to encode and decode Base64.
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.
Part one of the Ruby on Rails blog tutorial focuses on creating a Rails project and scaffolding a basic blog post data structure.
Before we start coding, we take some time to look at the game of 2048.
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.
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?
How do Ruby and Perl compare in function and form?
A quick tutorial taking you through using edit_line and edit_box elements in Shoes to provide text editing. Page 2.
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.
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.
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.
In this part, we'll implement a complete working application.
In this article we take a look at how to use jQuery and Sinatra to implement an AJAX interface.
Bundler is a gem dependency manager for Ruby.
Until Ruby 2.0, Ruby has not had true keyword arguments. You could simulate them using a hash, but as of Ruby 2.0 there's no longer any need to do that.
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.
Learn about the concepts of Ruby on Rails, a Model-View-Controller framework for creating database-driven websites in Ruby.
Running programs with Net::SSH is simple enough. The Session object gives you two convenient methods with which to accomplish this task.
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.
In the previous article, you learned what Rack is. Now, it’s time to start using Rack and serve up some pages.
You probably know about the 'require' method (yes, it is a method, it's not a keyword), but what about the 'load' method? What's so different about it?
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.
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.
Problem: Seemingly 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.
Great, now we know how to get to the Win32 API. Now, on to sending keystrokes using the Win32 API. Easy, right? Not really. It's not that hard, but it's not
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.
How to use Haml to create Sinatra views and layouts. Page 3.
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.
Directions of how to install the Tk GUI and its Ruby bindings on Windows, Linux and Mac OS X.
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.
How to get started in Sinatra, including how to use actions, parameters, ERB and views.
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.
A feature in Rails that protects against Cross-Site Request Forgery (CSRF) attacks.
Ruby programs rarely exist in their own little world. And while many choose to communicate over the internet, there's still plenty of need to access plain old files.
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.
This is a collection of Ruby links that need to be in your bookmarks. Read them, check them often, absorb them, because they're pure Ruby information.
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.
There are many hidden pitfalls when using temporary files. Ruby's Tempfile class solves many of these.
What is cloud computing? We asked Dave Vandervort of Xerox Innovation Group to help us answer that question and more.
class="no-js" itemscope itemtype="http://schema.org/Article" > itemprop="description" >DataMapper is
The Ruby on Rails router is responsible for determining which action to run depending on the HTTP request type and URL passed by the web server.
This Ruby script for Twitter is what's often referred to as a "mashup." Mashups interface one protocol
class="no-js" itemscope itemtype="http://schema.org/Article" > itemprop="description" >In order to analyze
I declared a variable in the global scope, and now I can't access it. What's going on here?
Running the Ruby profiler to determine which methods are most expensive and which need to be optimized.
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.
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.
Reddit wouldn't be much without users. In this tutorial, we install Devise as our authentication solution and get ready to integrate it.
Using the Twitter RubyGem, making API requests to Twitter is even easier than using the twitter method.
Sometimes blindly opening files just won't cut it, sometimes you need to know more information about a file before opening it.
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.
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.
Most non-compiled languages have some kind of eval function, which will take a string and execute it as code.
Method visibility is crucial to implement proper encapsulation. Ruby provides ways to not only hide instance variables, but to hide instance methods as well.
Before you can start making models, views and controllers for your web application, you need to generate a new applications. Rails projects are too complex to create by hand, you really do need an empty project to bootstrap you. It's not hard though, there's really only one command you need to know.
Variables are named references to objects in memory. Their several variants (local, instance, class, constant, etc) each have their own subtleties.
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.
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 to check POP3 email accounts 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.
Ruby does have threads, however the threading support in MRI (the most widely used Ruby interpreter) is not complete. It supports concurrency for IO-bound