yap emang bgitu caranya. pake Comparable <=> buat less than, greater than, sorting
ini udah pattern umum di OOP semoga bermanfaat Adinda Praditya wrote: > > Makasih atas ilmunya, makanya untuk menyatakan kesamaan, perlu overwrite > definisi kesamaan (equality) ini di class-nya, dalam hal ini > model-nya. Set > hanya atribut2nya saja yang sama, namun (mungkin, CMIIW) referensi-nya > tidak > perlu sama. Saya copas dari jawaban milis tetangga agar thread ini menjadi > bermanfaat: > > It all depends what we mean by *equal* (in human languages too). Quick > (simplified) summary of equality in Ruby: > > a) first, assert_equal is the same to the == operator > b) now, the == operator is inherited from Object, and it tests if two > *object > references* are identical. > c) however, the == operator is redefined by the usual classes String, > Array, > Hash, etc to mean *objects have identical content*. > > The 3 facts above indicate why the test behaved as you saw; the 2 Ruby > Recipe instances were tested for object identity, and the test failed, > because they were different instances. There is no error. > > However, if you wished the test to behave as you expected, simply redefine > the == method in Recipe > > class Recipe > def ==(other) > # compare properties of self against the ones of other > # self.x == other.x && self.y == other.y &&.... > end > end > > Demikian, mudah2an bermanfaat juga buat yang lain. > > Thanks semuanya, > > Dida > > . > > -- irfani http://irfani.web.id Y! irfani_s [Non-text portions of this message have been removed]

