ブロック内の DSL のユーザーによって宣言されたローカル変数にアクセスしたい。
例えば
class Scraper
def scrape!(&block)
a = block.binding
instance_eval &block
b = block.binding
p "b] Notice that the variable named variable no longer exists here..."
eval("p local_variables", a)
p "or here ..."
eval("p local_variables", b)
p "Although, when we rerun the proc, all is still as it was..."
pr = block.to_proc
pr.call
c = pr.binding
p "Still nothing here though..."
eval("p local_variables", c)
end
end
s = Scraper.new
s.scrape! do
variable = "some_value"
p "A] Notice that the variable named variable clearly exists here..."
p local_variables
end