From: Robert Klemme Date: 2008-10-22T23:39:23+09:00 Subject: Re: What exactly does "rubyish" or "ruby way" mean? 2008/10/22 Nit Khair : > Over the last month I have been reading a lot of blogs, searching, going > through source code of some apps and my pickaxe. I am still unable to > clearly understand what all "the ruby way" means. > > I will be perfectly happy if you can tell me: > > 1. phrases to google on, or check in pickaxe > 2. pointers to specific libraries or classes i can study > 3. link to any article I may have missed, or blog > > The only thing I can put down, that i have gleaned, is the usage of > procs/blocks, i.e. allowing the user to pass in blocks/yielding a value > or self. I liked the chapter on Ruby Tk in pickaxe (since I am hoping to > write a rubyish wrapper to ncurses). > > Surely there is more to the ruby way than blocks/procs/lambda. Would > really appreciate pointers. I cannot come up with a clear cut definition, but simplicity is certainly a part of it. Here's another example. If you want to group multiple values and use them as Hash key you can do MyKey = Struct.new :name, :age, :gender or you can do class MyKey attr_accessor :name, :age, :gender def eql? other name.eql? other.name and age.eql? other.age and gender.eql? other.gender end alias == eql? def hash name.hash ^ age.hash ^ gender.hash end end or even class MyKey def name; @name end def name=(x) @name = x end def age; @age end def age=(x) @age = x end def gender; @gender end def gender=(x) @gender = x end def initialize(name, age, gender) self.name = name self.age = age self.gender = gender end def eql? other name.eql? other.name and age.eql? other.age and gender.eql? other.gender end alias == eql? def hash name.hash ^ age.hash ^ gender.hash end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end