On Wed, Jan 5, 2011 at 11:24 AM, Adam Prescott <mentionuse / gmail.com> wrote=
:
> On Tue, Jan 4, 2011 at 9:00 PM, timr <timrandg / gmail.com> wrote:
>
>> class Object
>> =A0def singleton_class?
>> =A0 =A0self.singleton_methods.length =3D=3D 0 ? false : true
>> =A0end
>> end
>>
>
> Really small point here, and not really on topic, but this is a little
> around the houses and can be slightly improved:

I couldn't agree more!  Using ternary operator with "false" and "true"
is not needed most of the time. (Only exception I would concede is to
avoid leakage of references - but then you can as well do "!! expr".)

> class Object
> =A0def singleton_class?
> =A0 =A0!self.singleton_methods.empty?
> =A0end
> end
>
> Or just !=3D 0, since it'll return the true/false without the need for a
> ternary.

Or just

class Object
 def singleton_class?
   !singleton_methods.empty?
 end
end

Now we can wonder whether this is worth a method at all... :-)

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/