Created
July 3, 2014 21:01
-
-
Save dmcclory/bdb86e01217ae55f8021 to your computer and use it in GitHub Desktop.
Ruby Hoists Variables!
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
class Foo | |
def awesome(x) | |
y = 50 | |
x + y | |
end | |
end | |
set_trace_func proc { |event, file, line, id, binding, classname| | |
# output the binding at the start of any call to Foo#awesome | |
if id == :awesome and event == "call" | |
puts binding.eval("local_variables").inspect | |
end | |
} | |
Foo.new.awesome(100) | |
# if you run this the output will be: | |
# [:x, :y] | |
# so Ruby effectively hoists variables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment