-
-
Save anonymous/5b9037fe2c72b4f2428c 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 Helper | |
attr_reader :value | |
def Helper.included(parent) | |
parent.set_default_val | |
end | |
def set_default_val | |
@value = 42 | |
end | |
end | |
class MyClass | |
include Helper | |
end | |
MyClass.new.value #=> 42 | |
# Can I achieve this? Right now it fails with | |
# undefined method 'set_value' for MyClass | |
# I understand this error, 'parent' references the prototype of MyClass not an instance of the MyClass, but can I alter | |
# @value for that instance? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment