Ruby is an incredible, relatively modern programming language. Ruby borrowed nice ideas from multiple languages, but mainly from Perl. Some believe, Ruby was so refreshing and cool that Larry Wall had no other choice than to start to work on Perl 6 to incorporate some Ruby ideas back into Perl.
We held the lecture "Introduction to Ruby for Perl programmers" on our October 2003 meeting. The lecture unveils basic Ruby ideas and syntax constructions. The slides are online and you are welcome to look through them for self-education.
songs = [ { "artist" => "Deep Purple", "title" => "Child in Time", }, { "artist" => "Metallica", "title" => "Seek and Destroy", }, ] songs.each { |song| print song["title"], " (", song["artist"], ")\n" }
class Song attr_reader :title, :album, :artist def initialize(filename) @artist, @album, @title = filename.split("/")[-3..-1] @title.chomp!(".mp3") end def play puts @title end end song = Song.new("/data/music/ABBA/The Best of/Chiquitita.mp3") song.play
See more examples in the introduction lecture slides.
def method foo = nil array.each { |element| bar = element # element and bar are block local foo = element # while foo is not } end
Some of the missing Ruby features will be resolved in Ruby 2.
Perl 6 is a complete redesign of Perl 5 aiming to keep Perl relevant and dominant.
The future is going to be interesting with Perl 6 and Ruby 2 out.