Skip to content

Instantly share code, notes, and snippets.

@sunaot
Last active February 28, 2016 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunaot/8c3707dd5940fa0ae724 to your computer and use it in GitHub Desktop.
Save sunaot/8c3707dd5940fa0ae724 to your computer and use it in GitHub Desktop.
Dummy Object の作り方
require 'minitest/autorun'
class ModuleTest < Minitest::Test
def test_module_eval
debugger = Object.new
debugger.class.module_eval do
define_method(:debug) {|s| %(debug: #{s}) }
end
assert_equal 'debug: Hello', debugger.debug("Hello")
end
def test_meta_class
debugger = Object.new
class << debugger
define_method(:debug) {|s| %(debug: #{s}) }
end
assert_equal 'debug: Hello', debugger.debug("Hello")
end
# def (debugger = ()).debug(s); %(debug: #{s}) end
# はトリッキー?
def test_method
debugger = Object.new
def debugger.debug(s)
%(debug: #{s})
end
assert_equal 'debug: Hello', debugger.debug("Hello")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment