From: "Brian Schröder" Date: 2005-10-26T02:20:13+09:00 Subject: Re: Comparing Classes with Case ? On 25/10/05, Patrick Gundlach wrote: > > > > Just throwing in that it would not be a "BIG LOSS", not even a _big > > loss_ or a big loss, because you nearly never should test for the > > class of an object. > > Well, is the following the rare case of 'nearly never' or just > stupidity? > > > -------------------------------------------------- > #!/opt/ruby/1.8/bin/ruby -w > > class AnonUser ; end > class RegularUser < AnonUser ; end > class Developer < RegularUser ; end > class Guru < Developer ; end > class Sysop < Guru ; end > > brian=Guru.new > > # ... > > if Developer===brian > puts "ok, you are Developer" > end > if Sysop===brian > puts "you may shutdown the server" > end > -------------------------------------------------- > > # -> ok, you are Developer > > > Patrick > > One thing that may be bad about this approach is that you can't have multiple inheritance. You should at least use modules extending a User class, so that you allow for a more interesting hirarchie. And I don't see why User should not have a set of properties and methods like * developer? * sysop? etc. (Created dynamically, naturally :-) That are my thoughts about the approach. if user.developer? ### elsif user.sysop? ### end reads better in my opinion. regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/