Skip to content

Instantly share code, notes, and snippets.

@roidrage
Created March 28, 2009 20:33
Show Gist options
  • Save roidrage/87194 to your computer and use it in GitHub Desktop.
Save roidrage/87194 to your computer and use it in GitHub Desktop.
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