Closed postmodern closed 13 years ago
Yes, and this is a good thing in my book. The agreement is to see if an object answers #to_str to see if it is string-like.
So instead of doing explicit type checking you do message based "type checking", obj.respond_to?(:to_str)
instead of obj.kind_of?(String)
. I just want my thing to quack like a duck, not necessarily be a duck.
OK. I will have to be more careful when passing Parslet data to brittle interfaces (like Rack).
Note that this is just my personal opinion, @kschiess might think differently about that.
Rack does type checking with kind_of? ?
parslet implements several messages sent to slices differently than string does. Subtypes should behave like the supertypes, extending their functional domain, not limiting it. Since this is what parslet does, Parslet::Slice is no string.
It's really close though and it can be cast to_s. Have you got a concrete message you would like to send to slices and that should be implemented?
Parslet::Slice
does a good job mimicingString
, except that it does not inherit fromString
. This breaks code that explicitly checks forobj.kind_of?(String)
.