Last active
August 23, 2018 19:58
-
-
Save colinsurprenant/8787802 to your computer and use it in GitHub Desktop.
Ruby module instance variables
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
module SomeModule | |
module_function | |
def some_value; @some_value end | |
def some_value= v; @some_value = v end | |
end | |
SomeModule.some_value | |
# => nil | |
SomeModule.some_value = 1 | |
SomeModule.some_value | |
# => 1 | |
The instance variable @some_value belongs to module SomeModule which is an object instance of the Module class. | |
SomeModule.class | |
# => Module | |
SomeModule.instance_variables | |
# => [:@some_value] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment