Skip to content

Instantly share code, notes, and snippets.

@avescodes
Created July 14, 2010 18:35
Show Gist options
  • Save avescodes/475813 to your computer and use it in GitHub Desktop.
Save avescodes/475813 to your computer and use it in GitHub Desktop.
Apparently even if a local variable declaration isn't run it will still shadow a method with the same name
def thing
"ASDF"
end
puts thing #=> ASDF
if false
thing = "JKL:"
end
puts thing #=> nil
puts thing() #=> "ASDF"
# Edit: The work around (for the context I was working in)
thing = thing || thing() # self.thing would work too
@nathanbertram
Copy link

Neat, thanks for sharing. Never knew or have come across that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment