soulcutter/saxerator

Delegation removes functionality of 'is_a?' and 'kind_of?'

fanantoxa opened this issue · 2 comments

On this commit 220ac9b#diff-9bea3d175ebbd6d9862278ff1d538242
You've change inheritance to delegation.

But users expect kinda simple elements lite String, Integer, Array and I think it's fair.
so now to check that ArrayEllement is kinda Array we have to do:

some_item.is_a?(Saxerator::Builder::ArrayElement)

But it's not so usefull as

some_item.is_a(Array)
or
some_item.kind_of(Array)

@soulcutter What do you think about it?

@soulcutter
Readed http://words.steveklabnik.com/beware-subclassing-ruby-core-classes article.
But maybe we could override 'is_a' or 'kind_of' functions to check it? or it even worse idea?

99% of the time is_a? or kind_of? checks are not a good thing to do in Ruby. It's not idiomatic to do type checking where duck typing is the norm. With delegation you can still treat the object as an array, it just happens to wrap one to accomplish array-like features.

I definitely don't think overriding is_a? or kind_of? is a good idea.