Last active
December 30, 2015 12:59
-
-
Save PDegenPortnoy/7832722 to your computer and use it in GitHub Desktop.
Module setting instance variable and then checking for that variable in a containing class
This file contains 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
[1] pry(main)> module Helper | |
[1] pry(main)* def set_stuff | |
[1] pry(main)* @stuff = 'something' | |
[1] pry(main)* end | |
[1] pry(main)* end | |
=> nil | |
[2] pry(main)> class Controller | |
[2] pry(main)* include Helper | |
[2] pry(main)* def index | |
[2] pry(main)* set_stuff | |
[2] pry(main)* end | |
[2] pry(main)* end | |
=> nil | |
[3] pry(main)> c = Controller.new | |
=> #<Controller:0x1043bb488> | |
[4] pry(main)> c.index | |
=> "something" | |
[5] pry(main)> c.instance_variables | |
=> ["@stuff"] | |
[6] pry(main)> c.protected_instance_variables | |
NoMethodError: undefined method `protected_instance_variables' for #<Controller:0x1043bb488 @stuff="something"> | |
from (pry):15:in `__pry__' | |
[7] pry(main)> | |
[7] pry(main)> module Helper | |
[7] pry(main)* def set_stuff | |
[7] pry(main)* @stuff | |
[7] pry(main)* end | |
[7] pry(main)* end | |
=> nil | |
[8] pry(main)> c2 = Controller.new | |
=> #<Controller:0x10457d9b0> | |
[9] pry(main)> c2.index | |
=> nil | |
[10] pry(main)> c2.instance_variables | |
=> [] | |
[11] pry(main)> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment