Skip to content

Instantly share code, notes, and snippets.

/.rb Secret

Created October 2, 2015 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5b9037fe2c72b4f2428c to your computer and use it in GitHub Desktop.
Save anonymous/5b9037fe2c72b4f2428c to your computer and use it in GitHub Desktop.
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