-
-
Save banister/835013 to your computer and use it in GitHub Desktop.
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 MyMod | |
# store the variable on the module itself | |
var = "initial value" | |
# first method that accesses the var | |
define_method :get_var do | |
var | |
end | |
# second method that accesses the var | |
define_method :set_var do |value| | |
var = value | |
end | |
end | |
class MyClass | |
include MyMod | |
end | |
# show that we can use the methods | |
mc = MyClass.new | |
mc.get_var # => "initial value" | |
mc.set_var "altered value" | |
mc.get_var # => "altered value" | |
# so where is the variable stored? | |
mc.instance_variables # => [] | |
MyClass.instance_variables # => [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment