Learn more about Ruby, from its technical nature to its history and underlying philosophy, and find out how to use it on your N800/N810.
If computers are meant to serve us, then every device around us offers the potential for great personal empowerment. But in order to obtain these “superpowers” that exist around us, we must speak in their language. In other words, we must “speak” in a computer language. The way I “ask” computers - such as the N800 - what to do is via the use of scripting languages. As a scripting language polyglot, I only find great joy when using Ruby to communicate with computers. So with that in mind, I’ll show you how to install and run Ruby on your N800/810.
If you’re new to this, you may be asking, what is this Ruby language you speak so highly of?
Ruby can be described technically and philosophically.
Technically, Ruby is an open-source, interpreted scripting language for quick and easy object-oriented programming. It was developed in Japan by Yukihiro Matsumoto - aka “Matz” - and has been around since 1995. With an easy-to-use interpreter, familiar syntax, complete object-oriented functionality and powerful class libraries, Ruby has become a general-purpose language that can be applied to a broad range of areas, from text processing and CGI scripts to large-scale web applications such as Twitter and Basecamp.
Digging deeper, you’ll notice that as a scripting language, Ruby offers the ability to make operating system calls directly. It has powerful string operations and regular expressions a la Perl and has immediate feedback during development. Unlike other languages like Java, variable declarations are unnecessary. Additionally, variables are not typed and memory manage is also automatic. From an object-oriented programming perspective, everything in Ruby - as in Smalltak - is an object. If you’re familiar with classes, inheritance and methods, you’ll feel right at home with Ruby. Other features and concepts in Ruby’s bag of techno-jargon include singleton methods, iterators and closures, dynamic loading and threads, etc.
Philosophically, Ruby is a beautiful manifestation of Zen in zeros and ones. The way Matz describes it may give you a glimpse of what I’m talking about:
“Man is driven to create; I know I really love to create things. And while I’m not good at painting, drawing, or music, I can write software.”
- Matz
“I believe that the purpose of life is, at least in part, to be happy. Based on this belief, Ruby is designed to make programming not only easy, but also fun. It allows you to concentrate on the creative side of programming, with less stress.”
- Matz
I’m sure other programming languages carry a certain philosophy, but in Ruby, the mantras flow from the language straight into its user community.
“My conscience won’t let me call Ruby a computer language. That would imply that the language works primarily on the computer’s terms. That the language is designed to accomodate the computer, first and foremost. That therefore, we, the coders, are foreigners, seeking citizenship in the computer’s locale. It’s the computer’s language and we are translators for the world.
But what do you call the language when your brain begins to think in that language? When you start to use the language’s own words and colloquialisms to express yourself. Say, the computer can’t do that. How can it be the computer’s language? It is ours, we speak it natively!
We can no longer truthfully call it a computer language. It is coderspeak. It is the language of our thoughts.”
- From why the lucky stiff, a well known Ruby figure, in his hilarious book Why’s (poignant) Guide to Ruby.
Palpable aspects of Ruby philosophy in principle are discussed in The Tao of Programming by Geoffrey James. I’m referring to James’ Law of Least Astonishment. What is this law? It simply states that the program should always respond to the user in the way that least astonishes him the least. In the Ruby community we refer to it as the Principle of Least Surprise and it has been a guideline throughout the ongoing development of the Ruby language:
5.times { print “This is your N800, reporting for duty!” }
So now that you have a little sense of what Ruby is all about, let’s get it installed on your device.
Installing Ruby and the Ruby-Maemo Project
Currently, due to the vast amount of open source software in the Maemo community, a few implementations of the Ruby language exist. My favorite comes from the Ruby-Maemo project. This project not only has the standard distribution of the standard Ruby programming language, it also has extensions that have been customized to work with the Maemo platform - including the Hildon user interface.
Other than the user interface, Maemo includes custom libraries for IPC (interprocess communication) methods, managing internet connections (both wifi and Bluetooth), application configuration settings, alarm and timed events, authentication certificate management, desktop, status bar, navigation bar and configuration applets. There are also facilities for managing Bluetooth connections and devices as well as GPS (global positioning system) receivers. In other words, there’s hardly anything you can’t do natively with Ruby on your N800.
For a full installation we need to install the following packages and in this order:
1. libruby1.8
2. ruby1.8
3. ruby1.8-maemo
Fortunately, installation of these packages on OS2008 is a piece of cake. Just click on the package links above to start the download and the N800’s Application Manager will start the installation. You’ll be asked to “Open” or “Save” the file. Select “Open” and the Application Manager will handle the rest. If you are asked to add a repository to your Application Manager’s list, respond affirmatively.
Once you’ve installed all three packages and in that order, confirm that you have Ruby installed correctly by going to Utilities>X Terminal and type:
ruby -v
and then press “Enter”.
If the response is:
ruby 1.8.6 (2007-09-23 patchlevel 110) [arm-linux]
Congratulations. You’ve successfully installed Ruby on your device.
Now that’s installed. We should try an example.
On your PC or Mac open a text editor like Notepad or TextEdit and save the following script as ruby_test.rb.
#! /usr/bin/env ruby
require ‘hildon’
if $0 == __FILE__
GLib.application_name = “Basic Application”
program = Hildon::Program.instance
window = program.add_window Hildon::Window.new
window.signal_connect(’delete_event’) { Gtk.main_quit }
window.add Gtk::Label.new(”This is your N800, reporting for duty!”)
window.show_all
Gtk.main
end
Transfer this script from your computer either via Bluetooth or via USB and save it in the root of your device’s memory card. Then open a terminal - Utilities>X Terminal - and type:
cd /media/mmc2
It may be mmc1 depending on which memory card you installed it in. And then type:
ruby ruby_test.rb
You should see a Hildon UI window with the phrase “This is your N800, reporting for duty!” centered.
I’ll be writing more about Ruby in some upcoming articles. In the meantime, here are a few resources if you want to learning more about Ruby:
Ruby Programming Language
Why’s (poignant) Guide to Ruby
Try Ruby! in Browser
Share your own ideas and adventures with Ruby in the comments section.