Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created September 15, 2011 09:37
Show Gist options
  • Select an option

  • Save pasberth/1218904 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1218904 to your computer and use it in GitHub Desktop.
戻り値がnilであることを保証するだけのdefine_method
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