Created
April 5, 2013 22:50
-
-
Save 13k/5323320 to your computer and use it in GitHub Desktop.
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
| 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