in reply to perl primary, and keeping multiple languages in your head, and ruby
Played with Ruby a little bit. I have to be honest that I have never tried it before today.
It is quite a nice language in terms of OO and simplicity. Remind you of SmallTalk.
Just like any other languages, you might quickly find things that you don't like when you are finding things that you appreciate. It bothers me that Ruby does not support overloading of method. For example,
class A def initialize(attr1) @attr1 = attr1 end def initialize(attr1, attr2) @attr1 = attr1 @attr2 = attr2 end def tell() puts @attr1 end end class B < A def tell(blah) puts "blah" end end b = B.new("a", "b") b.tell()
This does not work, and complains that I passed 0 parameters to tell(), when it requires 1 parameter. So the one in subclass overwrites the one in super class.
But do those two initialize methods in class A both work? No, only the second one works. Basically, it does not support overloading, or put in this way, the signature of the method does not consider the parameter list, but only the name.
At the beginning, I thought that was bad that the method was overwritten and there was no warning, or error. Than my Perl knowledge comes in ;-) I ask myself "why not try to run it with ruby -w", maybe it has the -w switch just like Perl? That worked! and told me "warning: method redefined; discarding old initialize". So it does not supoprt overloading, but at least warns ;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl primary, and keeping multiple languages in your head, and ruby
by robharper (Pilgrim) on Sep 12, 2005 at 15:05 UTC |