Last active
December 18, 2015 22:09
-
-
Save tatat/5852487 to your computer and use it in GitHub Desktop.
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
| require 'active_support' | |
| module Definable | |
| def definable(name) | |
| define_method name do |value| | |
| (const_get(:ClassMethods, false) rescue const_set(:ClassMethods, Module.new)) | |
| .send(:define_method, name) { value } | |
| send(:define_method, name) { self.class.send name } | |
| end | |
| end | |
| end | |
| module A1 | |
| extend Definable | |
| definable :nyan | |
| end | |
| module B1 | |
| extend A1 | |
| extend ActiveSupport::Concern | |
| nyan :nyan1 | |
| end | |
| module A2 | |
| extend Definable | |
| definable :nyan | |
| end | |
| module B2 | |
| extend A2 | |
| extend ActiveSupport::Concern | |
| nyan :nyan2 | |
| end | |
| class C1 | |
| include B1 | |
| end | |
| class C2 | |
| include B2 | |
| end | |
| p C1.nyan #=> :nyan1 | |
| p C2.nyan #=> :nyan2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment