Skip to content

Instantly share code, notes, and snippets.

@nalabjp
Created August 5, 2017 17:46
Show Gist options
  • Save nalabjp/72c53b397008d08d90eee6180d059a19 to your computer and use it in GitHub Desktop.
Save nalabjp/72c53b397008d08d90eee6180d059a19 to your computer and use it in GitHub Desktop.
module DSL
def capture
'DSL#capture'
end
end
module Helper
def call_capture
capture
end
end
class Klass
def initialize(context)
@contenxt = context
end
def with_context(&block)
@contenxt.instance_eval(&block)
end
end
class SubKlass < Klass
def call_capture
with_context { capture }
end
end
class Pseudo
include DSL
include Helper
def run
puts "call `capture`: #{capture}"
puts "call `call_capture`: #{call_capture}"
k = SubKlass.new(binding.receiver)
puts "call `SubKlass#respond_to?(:capture)`: #{k.respond_to?(:capture)}"
puts "call `SubKlass#call_capture`: #{k.call_capture}"
end
end
Pseudo.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment