We could always do this:
class Negator
instance_methods.each { |x| undef_method x if x[-1] == ?? }
def initialize object
@object = object end
def method_missing name, *args, &block
name.to_s[-1] == ?? or super
not @object.__send__ name, *args, &block end end
class Object
def not
@__negator__ ||= Negator.new self end
alias_method :does_not, :not
alias_method :do_not, :not end
assert pet_class.ancestors.do_not.include?(Monster)
@pet = pet_class.new
assert @pet.does_not.respond_to?(:roar!)
3.times { @pet.feed Apple.new }
assert @pet.not.hungry?
(Finally a context in which the name ¡Ærespond_to?¡Ç sounds right.)
It would be nice to be able to get rid of those pesky parens, though:
assert pet_class.ancestors.do_not.include? Monster
assert @pet.does_not.respond_to? :roar!
Is there any word on the chances of this becoming allowed in the future?
I mean, is it definitely ruled out, or is there room for persuation?
--
Daniel Brockman <daniel / brockman.se>
So really, we all have to ask ourselves:
Am I waiting for RMS to do this? --TTN.