Last active
April 13, 2021 14:02
-
-
Save dentarg/435042ef12e6c5c81813de98fb3bc6f4 to your computer and use it in GitHub Desktop.
Ruby and "instance variable not initialized"
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
| irb(main):001:0> baz | |
| Traceback (most recent call last): | |
| 4: from /Users/dentarg/.rubies/ruby-2.7.1/bin/irb:23:in `<main>' | |
| 3: from /Users/dentarg/.rubies/ruby-2.7.1/bin/irb:23:in `load' | |
| 2: from /Users/dentarg/.rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>' | |
| 1: from (irb):1 | |
| NameError (undefined local variable or method `baz' for main:Object) | |
| irb(main):002:0> baz = "baz" if false | |
| => nil | |
| irb(main):003:0> baz | |
| => nil | |
| irb(main):004:0> $VERBOSE = true | |
| irb(main):005:0> | |
| irb(main):006:0> @baz = "baz" if false | |
| => nil | |
| irb(main):007:0> @baz | |
| (irb):7: warning: instance variable @baz not initialized | |
| => nil | |
| irb(main):008:0> @baz = nil | |
| irb(main):009:0> @baz | |
| => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment