A galactic gumshoe. A good one.

Ruby was a mid-80s radio drama trilogy (at least) produced by ZBS. A clever blend of sci-fi/cyberpunk and film noir styles (yes, I did say radio, but trust me, it fits).

Ruby herself is a futuristic private eye and a typical anti-hero. It’s just a bonus that she can slow time. Complete with far reaching, sinister conspiracies and more than it’s fair share of femme fatales, the series covers the mainstays of film noir. Moreover, I can’t help but think of Molly whenever I think of Ruby, and her Smith-Hitatchi "Godzilla" blaster and heat seeking “deedle darts” make me drool with gadget envy.

Ruby is a fully-object-oriented programming language created by Yukihiro Matsumoto which includes the strengths of Perl, Python, and other scripting languages. It is very popular in Japan and is getting more popular in the USA.

The syntax of Ruby is somewhat like that of Pascal. It features a lot of syntactic sugar to accomodate programming the the clearest possible form. The class system is fully-OO, and does not use multiple inheritance. A method called mix-in is used to include modules in a class to define interfaces, much like the similar idea Java uses.

This is the genealogy of the programming language Ruby:

Ruby is a child of Python, Smalltalk, Eiffel and Perl.
Ruby was born in year 1993.
It became Ruby 0.95 in year 1995.
It became Ruby 1.1 alpha 0 in year 1997.
It became Ruby 1.3.2 in year 1999.
It became Ruby 1.6.1 in year 2000, and has not changed much since that time.

This genealogy is brought to you by the Programming Languages Genealogy Project.

Minerology

Ruby and sapphire are the two varieties of the mineral corundum, that is, aluminum oxide (Al2O3). Red corundum is called ruby, and all other colors are called sapphire, but the distinction between ruby and pink or plum sapphire is so controversial that some jewelers may use Pantone color standards to distinguish them. (The name "ruby" is often a selling point for a particular gem.) They form hexagonal crystals and have a mineral hardness of 9, surpassed only by diamond in the natural world.

Large, gem-quality rubies have always been very rare. The huge gems described in medieval romances and oriental literature were most likely exaggerated by the imaginations the authors or were actually garnets or spinels.

History

The name ruby is derived from the Latin word for red, ruber. Ancient Orientals believed that rubies contained the spark of life, and that the ruby was self-luminous. Over the centuries, rubies have been regarded as symbols of freedom, charity, dignity and divine power. The Burmese believed that rubies ripened like fruit, and that a sapphire buried in the ground would eventually ripen into a ruby. A flawed ruby was considered "overripe".

In the Middle Ages, rubies were thought to bring good health and to guard against wicked thoughts, amorous desires and disputes. Their red color was said to cure bleeding. It was also believed that the ruby darkened in color to warn its owner of coming misfortunes, illness or death.

The first synthetic rubies were formed in 1902 by oxidizing aluminum powder in a hot gas flame, but the gems produced possessed gas bubbles and flecks of aluminum and were easy to identify. Today, it is possible to produce synthetic rubies that are indistinguishable from natural ones to all but the expert eye.

Today

Rubies are most frequently mined in Myanmar (known for clear, deep red "pigeon's-blood" rubies), Sri Lanka (medium-light red), Thailand (dark red to brownish-red), and across Africa (purplish-red). Heat treatment can be applied to improve color and eliminate imperfections, but this typically produces solidified borax within the gem which can be spotted under magnification. Because of their association with royalty, not to mention their rarity, large fine rubies are valued higher than a colorless diamond of the same size.

Ruby is the birthstone for the month of July and is the symbolic gemstone for the 40th wedding anniversary.

An important point about the Ruby Programming language and multiple inheritance - while Ruby does use modules which are roughly analogous to Java's interfaces it also supports delegation as a part of its standard library of objects.

One other facet to Ruby I feel would be criminal not to mention is its fully dynamic nature. Unlike Java and some other programming languages which have comparatively static object systems classes in Ruby can be modified/augmented at any time unless they're locked (or frozen in Ruby parlance). So if you want to change the way the base String class works you can just say:


class String
  def initialize(...)
    # New way for String to behave.  Maybe implement taint
    # checking?)
  end
end

and you've just globally patched the String object. You can even do this from within a debugger to test changes to your running program.

Ruby has this concept of blocks and iterators that form the basis of many the language's looping constructs - is in many cases objects of a specific type will define their own looping behavior.

Ruby is a hacker's dream :)

Ruby is a the pseudonym used by Lesley Rankine for her solo project following the split-up of Silverfish, the noise-rock outfit she once fronted. She started work on this project with producer Mark Walk (Ruby is the name of both of their maternal grandmothers) with whom she'd previously worked with while singing with the groundbreaking industrial collective Pigface.

Ruby, however, is a more chilled-out electronica influenced affair compared to Rankine's previous work with comparisons to some current trip-hop artists such as Sneaker Pimps mixed with Rankine's more rock-influenced roots. The album Salt Peter was released in 1995 and the belated follow-up Short-Staffed at the Gene Pool trudged out of the corporate quagmire Rankine found herself in by 2001. Remixes of both albums have also been released.


Ed. note: Ruby is indeed the name of the side project, but not a pseudonym for Lesley Rankine. See the Ruby page on Discogs. --mkb

Ruby is a programming language written by Yukihiro Matsumoto ("Matz"). It combines the cool features of Java, Scheme, Perl and Smalltalk into a coherent language which is very pleasant to use. Ruby is somewhat similar to Python, although personally I find Ruby is nicer. Ruby programmers are known as Rubyists.

There is an online book available at http://rubycentral.com/book/

Main features of Ruby:

  • Much of perl's built in data structures and syntax. You can use Regexps, hash tables and arrays.
    
    # arrays
    
    myarray = [1, 2, 3, 4]
    
    puts myarray[0]
    
    # hash tables
    
    english = {
            "one" => 1,
            "two" => 2,
            "three" => 3,
            "four" => 4,
    }
    
    puts english['one']
    
    # regexps
    
    if "shoenix" =~ /ni/ then
            puts "ni!"
    end
    
  • Object oriented with all the standard OOP features. OOP isnt a pain in the rear like it is with perl. Absolutely Everything is an object in Ruby - there are no base types. You can call methods on numbers, for example.
    # defining a new class
    
    class Shonky
       def monkey
          puts "monkey monkey monkey!"
       end
    end
    
    shoe = Shonky.new
    shoe.monkey()
    
    # absolute value
    
    test = -4
    puts test.abs()
    
    
  • Features from scheme like lambda and call/cc. When calling methods you can attach an associated code block so stuff like iterators can be done really expressively.
    
    mylist = [1, 2, 3, 4]
    
    # print each value in the list
    
    mylist.each { |i|
       puts i
    }
    
    # create a new anonymous function
    
    myfunc = lambda { |num| num+1 }
    
    puts myfunc.call(10)      # 11
    
    
  • The C API for writing extensions is really nice.
  • Comes complete with standard libraries for doing things like remoting (distributed Ruby) and web (HTTP).
  • Proper Mark and Sweep garbage collection.
  • Open Source!

The Ruby way

In using Ruby, you get a feel for "the Ruby way". There is a clear philosophy behind the language, though it is maybe not as loudly expressed as it is in the communities which surround other languages like Perl. The influence of Perl and Scheme is particularly evident in Ruby. Ruby encourages much looser programming than other languages - such as Duck Typing and not having to predeclare variables. Rubyists do not care about execution speed - rather, it optimises towards the programmer.

The future

At the time of writing Ruby has reached version 1.8. Work is soon to begin on Ruby 2.0 - this will be a major revision to the language. The new version will be based on a bytecode interpreter called Rite (cf. Parrot for Perl and Python). This will allow faster execution as well as native threading support.

You can find out more in Matz' Rubycon presentation here:

http://www.rubyist.net/~matz/slides/rc2003/

Ruby Iterators and Closures

One of the most beloved features of Ruby is its closure-based iterator syntax. It's been noted that this type of functionality can be replicated in some other languages, but tends not to be because the language itself makes it cumbersome. However, there is a unique magic in closures that is very hard to understand for PHP or Java programmers because those languages don't have closures, and even a lot of Perl and Javascript programmers because those languages don't emphasize closures. When I first came to Ruby I soon learned how to use its iterators, but it was several months before I actually did the mental gymnastics to learn what is the concept beneath the syntactic sugar.

First we need some brief definitions (the respective nodes have much more):

Closure: a function along with the environment (variables) in which it was defined.

Iterator: a means of looping through a collection (array, hash, etc) of some sort.

In Ruby an iterator is simply a method that somehow loops over the contents of an object. The object is often a collection type, such as Array or Hash, but an iterator can easily be defined to iterate over anything. For instance, Ruby's native File::open method can be called as an iterator where it returns one line from the file each iteration.

The magic of ruby iterators is that can call an anonymous function (known as a block in Ruby) that is passed in when the iterator is called. This block looks just like a block in many other languages. Example:

a = [ 1, 2, 3 ]
a.each { |x| print x }

would produce output:

123

So, to clarify the syntax:

  • a is an array object
  • each is a basic iterator method defined for the Array class
  • { } define the block (anonymous function)
  • |x| is the parameter passed to the block inside the iterator
  • print x is the body of the block.

Other than being concise, what's so great about this syntax? How would it be any different from a traditional loop such as:

a = [ 1, 2, 3 ]
for i in 0...a.size
  print a[i]
end

The iterator is a function that defines some overall semantics of an operation; like how to loop over the members of this collection, and what to return. However, by including a block the function is then infinitely customizable by the programmer. So in effect you are decoupling the overall actions to be performed on the collection (in this case: loop through it) from the actions to be performed on each individual member (in this case: print it). However there's more to it than that.

Ruby Iterators

Let's look at how iterators are implemented. The Array.each method could be defined internally like this:

def each
  for i in 0...size
    yield(self[i])
  end
end

The critical part here is the yield function. This is what calls the block that is passed in. As you can see, each is pretty straightforward. each doesn't return anything, but most other iterators do. Take find, for example:

def find
  for i in 0...size
    if yield(self[i])
      return self[i]
    end
  end
  return nil
end

To continue with our previous example, you can call find like this:

a = [ 1, 2, 3 ]
if a.find { |x| x == 2 }
  print "FOUND 2!"
else
  print "DIDN'T FIND 2!"
end

Just to stem any confusion over how this is interpreted, note that the last value evaluated in a ruby function is automatically returned even if there is no explicit return statement. So in this case, the array items are passed to the block one by one and the expression x == 2 is evaluated and returned to the find function which returns immediately if the block returns a value that evaluates to true, or else returns nil if it gets to the end without finding such an element.

Closures

Hopefully by now you are starting to see the utility of Ruby's block-based iterators. Certainly blocks used this way can be valuable. However, so far nothing I've shown has required closures. That is to say, we aren't using any previously defined variables in our blocks. So the block could just as well be a traditional method or function defined with a name, and passed to the iterator by reference—something you could do in PHP or Java although it wouldn't be pretty.

No, the true value of Ruby blocks come from the closure property. Consider the following example:

birthdays = ["June 10", "August 20", "December 19"]
my_birthday = database.get_my_birthday()
birthdays.find { |x| x == my_birthday }

Without closures, my_birthday would have to be a parameter passed into the block. But that would require the find method to pass two arguments in its yield statement. Even worse, find would need to have my_birthday passed into it so it could in turn pass it to the block. So we would have something like:

birthdays = ["June 10", "August 20", "December 19"]
my_birthday = database.get_my_birthday()
birthdays.find_equal_to(my_birthday) { |x,y| x == y }

Which is not only longer and uglier than the original with closures, but is far too specific to be of any general use. At this point you may as well hardcode the block into the find_equal_to method (renamed for clarity). Sure, you can still customize the block, but you've lost 99% of the utility of the find method, so why bother when you can probably write a handful of these functions to take care of all the functionality your program needs.

Blocks in General

Earlier I mentioned decoupling the operations on a collection from the operations on its individual members. This is the ruby iterator paradigm. However, it's of critical importance to understand that ruby blocks allow decoupling to occur anywhere—not just between collections and their members. Any method can take a block as its last parameter, and can yield to that block whenever it chooses. Iterators are just the most common use of blocks in ruby, but they are far from being their only use.

In general blocks allow on-the-fly specialization of methods. Without closures a block would be nothing more than an anonymous function, so you could specialize the code of the method but not the data. With closures all your local variables come along for the ride, so your custom code has an infinite amount of context within which to work. I would argue that customizing on the data is the more useful half of the equation since algorithms tend to be general whereas data is unique to each application.

Ru"by (?), n.; pl. Rubies (#). [F. rubis (cf. Pr. robi), LL. rubinus, robinus, fr. L. rubeus red, reddish, akin to ruber. See Rouge, red.]

1. Min.

A precious stone of a carmine red color, sometimes verging to violet, or intermediate between carmine and hyacinth red. It is a red crystallized variety of corundum.

⇒ Besides the true or Oriental ruby above defined, there are the balas ruby, or ruby spinel, a red variety of spinel, and the rock ruby, a red variety of garnet. <-- artificially produced variants are used in jewelry and in lasers. -->

Of rubies, sapphires, and pearles white. Chaucer.

2.

The color of a ruby; carmine red; a red tint.

The natural ruby of your cheeks. Shak.

3.

That which has the color of the ruby, as red wine. Hence, a red blain or carbuncle.

4. Print.

See Agate, n., 2.

[Eng.]

5. Zool.

Any species of South American humming birds of the genus Clytolaema. The males have a ruby-colored throat or breast.

Ruby of arsenic, Ruby of sulphur Chem., a glassy substance of a red color and a variable composition, but always consisting chiefly of the disulphide of arsenic; -- called also ruby sulphur. -- Ruby of zinc Min., zinc sulphide; the mineral zinc blende or sphalerite. -- Ruby silver Min., red silver. See under Red.

 

© Webster 1913.


Ru"by, a.

Ruby-colored; red; as, ruby lips.

 

© Webster 1913.


Ru"by, v. t. [imp. & p. p. Rubied (?); p. pr. & vb. n. Rubying.]

To make red; to redden.

[R.]

Pope.

 

© Webster 1913.

Log in or register to write something here or to contact authors.