Florian Groß <florgro@gmail.com> writes:
David A. Black wrote:
extending the system so that it could match, for example,
"an array of objects that respond to ''" (or something along those
lines)?I wonder if he could just support objects that implement === which
would give you Range and Module support and ruby-contract support for
free.But how is this related to your quote at all? ruby-contract offers a Check::Quack[:message] adaptor that implements === via respond_to?() --
I wonder if it would be a good idea to define Symbol#=== which would
be used like this:first = case obj
when :first then
obj.first
when :fetch then
obj.fetch(0)
when :at then
obj.at(0)
when : then
obj[0]
end
While I can see your intention, please don't do that. Often, people
want to compare Symbols and Symbols (they are perfect for that). It
is already very confusing that String !=== String (what is the most
elegant way to case compare classes against classes, btw?).
case obj.quack
when :first
when :fetch
...
end
would be nice to have, though.
···
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org