Created
March 28, 2009 20:33
-
-
Save roidrage/87194 to your computer and use it in GitHub Desktop.
This file contains 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 Speech | |
def self.included(base) | |
base.send :include, Speech::Support | |
end | |
end | |
module Speech::Support | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def singleton_class | |
class << self; self; end | |
end | |
def speak | |
puts "in #{__LINE__} from #{caller[0]}" | |
puts 'say: module method' | |
super | |
end | |
def can_speak | |
class_eval do | |
def self.speak | |
puts "say: class_eval" | |
super | |
end | |
end | |
class << self | |
define_method :speak do | |
puts "in #{__LINE__} from #{caller[0]}" | |
puts "say: class << self" | |
super() | |
end | |
end | |
self.class.instance_eval do | |
define_method :speak do | |
puts "in #{__LINE__} from #{caller[0]}" | |
puts "say: class.instance_eval" | |
end | |
end | |
end | |
end | |
end | |
class Matt | |
def self.speak | |
puts "real class method" | |
super | |
end | |
include Speech | |
can_speak | |
end | |
Matt.speak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment