Created
August 17, 2012 02:26
-
-
Save MarkBennett/3375397 to your computer and use it in GitHub Desktop.
How do Ruby closures work?
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
greeting = "Hello" | |
def greeter | |
puts greeting | |
end | |
greeter | |
# undefined local variable or method `greeting' for main:Object (NameError) |
If you want a lexical closure you need to use define_method
instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Methods are not lexical closures, so I'm not sure what you're asking here?