Last active
October 20, 2020 02:11
-
-
Save serradura/9a1bffb8d79706eb699eca76551747cb to your computer and use it in GitHub Desktop.
Create a proxy to track the usage of the Ruby send 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
module Words1 | |
def self.foo; "foo1"; end | |
def self.bar; "bar1"; end | |
end | |
module Words2 | |
extend self | |
private | |
def foo; "foo2"; end | |
def bar; "bar2"; end | |
end | |
module Sender | |
def self.call(sub, method_name, *args, &block) | |
puts "Caller: #{caller(1).first}" | |
puts "Source Location: #{sub.method(method_name).source_location}" | |
return sub.send(method_name) if args.empty? && !block | |
return sub.send(method_name, *args) if !args.empty? && !block | |
return sub.send(method_name, *args, &block) if !args.empty? && block | |
end | |
end | |
module RenderWord | |
def self.call(strategy, word) | |
# puts strategy.send(word) | |
puts Sender.call(strategy, word) | |
end | |
end | |
RenderWord.call(Words2, :foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment