Created
December 3, 2013 14:41
-
-
Save anonymous/7770260 to your computer and use it in GitHub Desktop.
proxying instance_eval with a local variable issue: POC
This file contains 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
require 'watir-webdriver' | |
class BrowserProxy | |
instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/ } | |
def my_awesome_method | |
"you just called an awesome method!" | |
end | |
def initialize(browser = :firefox, *args, &block) | |
@target = Watir::Browser.new(browser, *args, &block) | |
end | |
def method_missing(name, *args, &block) | |
@target.send(name, *args, &block) | |
end | |
end | |
proxy = BrowserProxy.new | |
real = Watir::Browser.new | |
test = "VARIABLE IN SCOPE" | |
real.instance_eval "puts(test)" | |
proxy.instance_eval "puts(test)" | |
##output: | |
#VARIABLE IN SCOPE | |
# from browser_wrapper.rb:19:in `instance_eval': wrong number of arguments (0 for 2..3) (ArgumentError) | |
# from (eval):1:in `method_missing' | |
# from browser_wrapper.rb:19:in `instance_eval' | |
# from browser_wrapper.rb:19:in `method_missing' | |
# from browser_wrapper.rb:29:in `<top (required)>' | |
# from -e:1:in `load' | |
# from -e:1:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment