Skip to content

Instantly share code, notes, and snippets.

@thisismydesign
Created August 21, 2018 12:46
Show Gist options
  • Save thisismydesign/a07b034494e33ea0dc125eb30733cf2d to your computer and use it in GitHub Desktop.
Save thisismydesign/a07b034494e33ea0dc125eb30733cf2d to your computer and use it in GitHub Desktop.
Ruby: how to use self.included meaningfully, solution and use case
module CreateClassMethodsUponInclude
def self.included(base)
base.define_singleton_method :included do |base|
base.extend(self)
end
end
end
module MyModule
include CreateClassMethodsUponInclude
def something
'something '
end
end
class MyClass
include MyModule
end
p MyClass.something + MyClass.new.something + 'awesomeness'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment