Skip to content

Instantly share code, notes, and snippets.

@ctide
Forked from moxley/my_class.rb
Created September 20, 2012 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctide/3753494 to your computer and use it in GitHub Desktop.
Save ctide/3753494 to your computer and use it in GitHub Desktop.
Weird Ruby Behavior
class MyClass
def value
"VALUE!"
end
def do_something
puts defined?(value) # Outputs "method"
puts value # Outputs "VALUE!"
if false
value = 'abcdef' # Should not execute
end
puts defined?(value) # Outputs "local-variable"
puts value # Outputs nothing
end
end
MyClass.new.do_something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment