Skip to content

Instantly share code, notes, and snippets.

@rbxbx
Created October 23, 2010 04:28
Show Gist options
  • Select an option

  • Save rbxbx/641770 to your computer and use it in GitHub Desktop.

Select an option

Save rbxbx/641770 to your computer and use it in GitHub Desktop.
Object.antialias_method
class Object
def self.antialias_method(new_name, old_name)
define_method(new_name) { !send(old_name) }
end
end
require 'test/unit'
class AntialiasTest < Test::Unit::TestCase
class Person
def registered?
true
end
antialias_method(:unregistered?, :registered?)
end
def test_antialias_method_defines_inverse_method
assert_respond_to(Person.new, :unregistered?)
assert_equal(Person.new.unregistered?, false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment