Ruby

 By Simon Bisson

This new dynamic scripting language is fast becoming popular. Simon Bisson checks out Ruby and Rails.

HardCopy Issue: 39 | Found In: Development | Published: 01/02/2008 | Last Revision: 06/07/2010

First released in 1995, Ruby is one of the few programming languages to come from outside North America and Western Europe. Like the Brazilian Lua, the Japanese-created Ruby is a dynamic scripting language with a close relationship to the ever popular Perl. With Perl 6 still under development, Ruby has been enthusiastically adopted by many Perl developers and has become one of the fastest growing modern languages. Its creator Yukihiro ‘matz’ Matsumoto describes Ruby as being, “Simple in appearance, but is very complex inside, just like our human body.” Like most modern languages Ruby is object-oriented with every data type treated as an object – including some that other languages define as primitives. There’s no multiple inheritance, simplifying object creation. Ruby is also best treated as a procedural programming language though it does offer some functional programming features. You’ll find that Ruby mixes concepts from both Perl and Smalltalk, making it easy to learn and quick to produce production-ready code. You can also use Ruby as a shell-scripting language with its own command line interpreter, irb. You can use irb to quickly test programme syntax. It’s easy to learn Ruby but there are some issues that can cause confusion. One is the use of capital letters in variable names to denote a constant. Local variables must start with a lower case letter. There’s also an issue in that many versions of Ruby don’t support a character data type, making string manipulation rather more complex than in string processing languages like Perl. However there is support for Perl-like regular expressions, making it easy to develop complex input and output processing rules. You can use blocks to add functional programming features to Ruby. A block has closure, which is used to describe just how a method should use it, and a block can be used more than once in a method. Blocks let you pass code to methods. This approach allows you to have generic methods that can be given different functions depending on how they’re called. It’s an approach that works well when using test-first methodologies as a block can be a unit test that can inspect the internal operations of a method. Ruby probably wouldn’t have been so without Rails. The combination of the Rails Web application development framework and the Ruby language has become known as Ruby on Rails and has become one of the key technologies when developing Web 2.0 applications. It’s even bundled with the latest release of Apple’s OS X operating system.

Ruby tools

There are already a wide range of Ruby-compatible editors with code highlighting support and debugger integration in most developer editors. Ruby as a dynamic language is well supported and there are an increasing number of Rails development environments from a mix of open source and commercial backgrounds.

The Eclipse-based Aptana IDE supports Ruby as well as Rails. It’s worth looking at Aptana if you’re planning on building Rails-based Web applications and want the familiarity of the Eclipse environment. The Aptana tools are based on the open source RadRails toolkit and include tools for editing RHTML files, as well as debugging code running on remote servers. As part of a complete Web application development platform, the Aptana IDE means developers can use the same IDE to work on the AJAX and HTML elements of a site – and even deliver it in an Apple iPhone format.

Ruby in Steel is a British Ruby on Rails IDE which plugs into Microsoft’s Visual Studio 2005. It integrates with Visual Studio’s IntelliSense code completion tools, and adds tools to help link Ruby to .NET. An integrated debugger lets you use familiar debugging features, while scripts handle generating Rails application scaffolds and application elements. See www.sapphiresteel.com for more information.

CodeGear has also released a Ruby on Rails IDE called 3rdRail. 3rdRail offers a mix of features, including wizards to simplify application creation and Web development tools to support the development of Rails-based Web applications. See www.greymatter.com/3rdrail for details.

Originally developed to build the popular Basecamp Web 2.0 project management tool, Rails was released as an open source Web application development framework. It’s just reached version 2.0 and is used to run many popular Web applications, despite its poor scaling performance. Rails’ strength is its support for ‘convention over configuration’. The approach taken by the Rails development team is intended to simplify application development. Based on the common Model-View-Controller design pattern, Rails uses AJAX to deliver user experiences while automating database connections. Rails applications don’t need complex configuration files. A Sales object can be connected to a Sales table in a database automatically. Applications begin empty, with collections of the files and folders you need to run a Web application. Databases can be given names that allow Rails to discover the tables that you’ll be using. Once the database is in place Rails generates the application scaffolding – the basic files used for the application. Details can be added by editing the generated Ruby files, which can also be used to give applications a custom look and feel. The upcoming Ruby 2.0 addresses many concerns about the performance of Ruby’s interpreter by building on the YARV virtual machine (which will also be used in Ruby 1.9). YARV is expected to improve Ruby’s performance by up to 10 times, with Ruby on Rails applications running 15 per cent faster. There are other tools for deploying Ruby code including Iron Ruby, a .NET implementation of Ruby that is being used to demonstrate Microsoft’s new Dynamic Language Runtime. This can be used to write Silverlight 2.0 applications, taking Ruby in a whole new direction. You can also use JRuby to write Ruby code that compiles as Java. Like Perl, Ruby has a built-in package management system which lets you download modules and add-ins as required. Gems is a powerful tool that makes Ruby a very flexible alternative to Perl for script-based applications and Web development. With support coming from companies like Microsoft, it’s clear that Ruby has a promising future.

How to shoot yourself in the foot in Ruby:

# Your foot is ready to be shot in roughly five minutes but you just can’t find anywhere to shoot it.

Share and Bookmark  

Comments

Be the first to comment about this article...

Leave a comment

You must login to place comments.

Skin Border Image

Article Resources

Skin Border Image