From: Tobias Reif Date: 2001-11-29T22:48:30+09:00 Subject: [ruby-talk:26894] short article draft for review Hi, here is a draft for a very short article about Ruby. All in all I want to leave it like it is, but if you find major errata/bugs/issues, please post corrections/fixes. (or mail 'em offlist; it's probably not worth a big thread) --------------------------------------- Ruby makes me feel good Ruby is a very nice object-oriented programming language. I'm amazed by it again and again, because it's simple, powerful, fun, and magic. It's created by Yukihiro "Matz" Matsumoto, and the homepage is www.ruby-lang.org/en/ . It's open source, and runs on many platforms, including Linux and Windows. Ruby is still young. On the one hand, this means that there aren't as many libraries in place as there could; on the other hand, it means that there's still much room to get involved. Ruby is my first full programming language. I started with some others before, but they didn't inspire me. With Ruby, I'm having fun. One guy at ruby-talk (the main list) said many of the participants at his Ruby workshop were smiling, instead of looking frustrated. Others say, their thoughts flow directly into the code. Sometimes I think: "I have a good idea how to implement this; I'll do a quick outline, and work on it later." But in Ruby, there's not much difference between high level pseudo code expressing the intentions, and the actual code. Many times, my Ruby programs surprise me: they run before I think they could. Ruby is a very high level language, featuring descriptive naming among many other nice concepts; nice, readable, and maintainable code can be written. Here are just a few of the things I like about Ruby: ---------------------------------------- Easy to extend existing classes: class Numeric def pos if self < 0 0 else self end end end puts 4.pos puts 0.pos puts -4.pos # 4 # 0 # 0 ---------------------------------------- Iterators: for first in 1..2 do for second in 1..3 do puts first.to_s + '.' + second.to_s end end # 1.1 # 1.2 # 1.3 # 2.1 # 2.2 # 2.3 ---------------------------------------- Recursion, blocks as arguments: def upto limit,current=1,&block yield current if current < limit upto limit,current+=1,&block end end upto(2) do |integer| puts 'line' + integer.to_s end # line1 # line2 ---------------------------------------- Objects: class Digits_to_english < String def to_e self.scan(/\d/).map do |digit| case digit when '0' then 'zero' when '1' then 'one' when '2' then 'two' when '3' then 'three' when '4' then 'four' when '5' then 'five' when '6' then 'six' when '7' then 'seven' when '8' then 'eight' when '9' then 'nine' end end end end d2e = Digits_to_english.new '55793' puts d2e puts d2e.to_e # 55793 # five # five # seven # nine # three ---------------------------------------- * Very high level * Pure OO from the beginning OO skills are not required to get started. * Easy to use: Simple stuff is simple, complex stuff isn't complicated. * Interpreted: no need to compile. (That's how the current main implementation works; other models are thinkable) * Allrounder: Good for serveside, GUI, commandline, distributed apps and more. * Human oriented: One can be creative, instead of being intimidated by complexity. * Elegant and expressive control structures: Readable and maintainable code is possible * The principle of least surprise Many times, things work as expected. On http://www.pinkjuice.com/howto/ I collected some links that were helpful for me when I started. There also is a howto about generating and serving SVG, featuring tips, examples, and code. There are links to the Ruby interpreter, including an easy Windows installer. Also check: The Pickaxe - A very good book http://www.rubycentral.com/book/ Ruby Book List http://www.rubygarden.org/ruby?RubyBookList Ruby Documents http://www.ruby-lang.org/en/doc.html go_to('www.ruby-lang.org').get(ruby).play.create.have_fun ;) Tobi --------------------------------------- Tobi -- Tobias Reif http://www.pinkjuice.com/myDigitalProfile.xhtml go_to('www.ruby-lang.org').get(ruby).play.create.have_fun http://www.pinkjuice.com/ruby/