Created
October 23, 2010 04:28
-
-
Save rbxbx/641770 to your computer and use it in GitHub Desktop.
Object.antialias_method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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