Last active
August 29, 2015 13:56
-
-
Save speed-of-light/8950089 to your computer and use it in GitHub Desktop.
Ruby Idioms
This file contains hidden or 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 Foo | |
| def self.included base | |
| base.send :include, InstanceMethods | |
| base.extend ClassMethods | |
| end | |
| module InstanceMethods | |
| def bar1 | |
| 'bar1' | |
| end | |
| end | |
| module ClassMethods | |
| def bar2 | |
| 'bar2' | |
| end | |
| end | |
| end | |
| class Test | |
| include Foo | |
| end | |
| Test.new.bar1 # => "bar1" | |
| Test.bar2 # => "bar2" | |
| #from http://stackoverflow.com/questions/10692961/inheriting-class-methods-from-mixins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment