Skip to content

Instantly share code, notes, and snippets.

@dmcclory
Created July 3, 2014 21:01
Show Gist options
  • Save dmcclory/bdb86e01217ae55f8021 to your computer and use it in GitHub Desktop.
Save dmcclory/bdb86e01217ae55f8021 to your computer and use it in GitHub Desktop.
Ruby Hoists Variables!
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