Created
May 16, 2015 05:43
-
-
Save uzbekjon/34eb00c52668c2049ded to your computer and use it in GitHub Desktop.
Ruby "append_features" method demo
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 MyModule | |
def self.append_features(base) | |
puts "IN 'append_features':" | |
puts " - BEFORE execution: #{base.instance_methods.include? :some_method}" | |
super | |
puts " - AFTER execution: #{base.instance_methods.include? :some_method}" | |
end | |
def self.included(base) | |
puts "IN 'included': #{base.instance_methods.include? :some_method}" | |
end | |
def some_method() end | |
end | |
class MyClass | |
include MyModule | |
end | |
# Output: | |
# | |
# IN 'append_features': | |
# - BEFORE execution: false | |
# - AFTER execution: true | |
# IN 'included': true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment