Skip to content

Instantly share code, notes, and snippets.

@da3mon
Created April 12, 2012 23:09
Show Gist options
  • Save da3mon/2371683 to your computer and use it in GitHub Desktop.
Save da3mon/2371683 to your computer and use it in GitHub Desktop.
defiling science
class AttributeError < RuntimeError; end
def foo
return @foo if defined?(@foo)
raise AttributeError
end
foo
@foo = :foo
foo
foo = nil
foo
#[1] pry(main)> class AttributeError < RuntimeError; end
#=> nil
#[2] pry(main)> def foo
#[2] pry(main)* return @foo if defined?(@foo)
#[2] pry(main)* raise AttributeError
#[2] pry(main)* end
#=> nil
#[3] pry(main)>
#[4] pry(main)> foo
#AttributeError: AttributeError
#from (pry):4:in `foo'
#[5] pry(main)>
#[6] pry(main)> @foo = :foo
#=> :foo
#[7] pry(main)>
#[8] pry(main)> foo
#=> :foo
#[9] pry(main)>
#[10] pry(main)> foo = nil
#=> nil
#[11] pry(main)> foo
#=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment