Created
September 15, 2011 09:37
-
-
Save pasberth/1218904 to your computer and use it in GitHub Desktop.
戻り値がnilであることを保証するだけのdefine_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.void funcname, &func | |
| define_method(funcname) { |*args| func.call(*args); nil } | |
| end | |
| end | |
| if __FILE__ == $PROGRAM_NAME | |
| require "test/unit" | |
| class SampleClass | |
| void :homuhomu do |str| | |
| $str = str | |
| end | |
| end | |
| class TesVoid < Test::Unit::TestCase | |
| def setup | |
| "" | |
| end | |
| def test_void | |
| assert_equal nil, SampleClass.new.homuhomu("string") | |
| assert_equal "string", $str | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment