Skip to content

Instantly share code, notes, and snippets.

@colinsurprenant
Last active August 23, 2018 19:58
Show Gist options
  • Save colinsurprenant/8787802 to your computer and use it in GitHub Desktop.
Save colinsurprenant/8787802 to your computer and use it in GitHub Desktop.
Ruby module instance variables
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