Skip to content

Instantly share code, notes, and snippets.

@sunaot sunaot/dummy_object.rb
Last active Feb 28, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.