Skip to content

Instantly share code, notes, and snippets.

@13k
Created April 5, 2013 22:50
Show Gist options
  • Select an option

  • Save 13k/5323320 to your computer and use it in GitHub Desktop.

Select an option

Save 13k/5323320 to your computer and use it in GitHub Desktop.
class C
attr_reader :read_only
def assert(assertion, message="assertion failed")
raise RuntimeError, message unless assertion
end
def initialize
@read_only = 13
assert read_only == 13
end
def m
assert read_only == 13
assert !read_only.nil?
# trying to set a local variable named `read_only`
read_only = \
# probably by now Ruby set a ref in the local binding for `read_only`
# so it is now nil ?
read_only.dup
end
end
C.new.m # => raises TypeError: can't dup NilClass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment