Jens Wille
9/2/2008 12:24:00 PM
Robert Dober [2008-09-02 14:08]:
> On Tue, Sep 2, 2008 at 1:04 PM, Jens Wille <jens.wille@uni-koeln.de> wrote:
>> done. more or less ;-) i kept hashes, since i sometimes like 'em
>> better. would you prefer === over is_a? in this case? if so, why?
>
> Although is_a? is more readable the #=== operator is a very powerful
> concept of ruby, using it and thus understanding its semantics allows
> us to use/understand case statements more efficiently, a problem that
> frequently comes up with nubies.
> I guess most people prefer this code
>
> case args.first
> when String, Symbol
> ...
> when Enumerable
> ...
> end
>
> to
>
> if args.first.is_a?( String ) || ...
> ...
> elsif args.first.is_a?( Enumerable )
>
> end
FULL ACK up to this point.
> Somehow I feel therefore the use of Class#=== preferable to
> Object#is_a?
well, i don't ;-) as you said, the latter reads much nicer and is a
straight translation of what i wanted to say. the former just feels
"the wrong way around" to me. and, you see, with the case statement
it's the right way again: you compare an object to a class.
> but I would not argue with people using is_a? ;).
ok, then i won't continue doing so either *g*
cheers
jens