[Plugin] AttributeInspector 1.1.1 β 2014-05-08
-
BTW... you can currently use the triple equal method with
Lengthclass, so this will work:
true === length_value || false === length_value -
@aerilius said:
Or shouln't ruby have a "Boolean" super class of which TrueClass and FalseClass are subclasses?
type = (value.is_a?(TrueClass) || value.is_a?(FalseClass)) ? "Boolean" : value.class.to_sI always wondered why not ?
One thing I have done in the past is create a
boolean?()query method forObject(or something else likeComparable.
Now this is frowned upon, and I never released it, just suggested, or had it in my test scripts.def boolean?() is_a?(TrueClass) || is_a?(FalseClass) end unless method(;boolean?)
AND / OR, ... create a
Booleanmixin module, and then mix it into onlyTrueClassandFalseClass. The mixin module may not actually need any additional functionality, at all ?Then the
kind_of?(aliasis_a?,) methods will return the appropriatetrueorfalseusing aBooleanclass argument, for any, and ALL objects.
The===will also work for all objects, which makes case statements work:
Boolean === value
Whichever one (or both,) ya'll want, would need to be adopted as an API extension, by the community. (And we'd need to convince the Trimble team to add it.)
-
The Length class is a bit of a special case. It's trying to be a sub-class of Float - but the Ruby API doesn't really let you do this. So there's some hackery in the background to make it work. I'll file an issue to see if we can avoid the argument error.
-
Thanks TT.
Just returning
falsewould be preferable, instead of raising anArgumentError(when reallyTypeErroroccurs.) -
Yea, there's a few annoying inconsistency where the correct error isn't raised.
Advertisement