Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created October 12, 2008 06:47
Show Gist options
  • Save ELLIOTTCABLE/16371 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/16371 to your computer and use it in GitHub Desktop.
class Foo
def self.method_added(meth); puts "Foo#method_added: #{meth}"; end
def self.singleton_method_added(meth); puts "Foo#singleton_method_added: #{meth}"; end
# Singleton
class << self
def self.method_added(meth); puts "singleton#method_added: #{meth}"; end
def self.singleton_method_added(meth); puts "singleton#singleton_method_added: #{meth}"; end
# Metasingleton
class << self
def self.method_added(meth); puts "metasingleton#method_added: #{meth}"; end
def self.singleton_method_added(meth); puts "metasingleton#singleton_method_added: #{meth}"; end
# Metametasingleton
class << self
def self.method_added(meth); puts "metametasingleton#method_added: #{meth}"; end
def self.singleton_method_added(meth); puts "metametasingleton#singleton_method_added: #{meth}"; end
end
end
end
end
puts '--- -- --- ! --- -- ---'
class Foo
def instance_method; end
def self.singleton_method; end
class << self
def instance_method_on_singleton; end
def self.singleton_method_on_singleton; end
end
end
Foo#singleton_method_added: singleton_method_added
singleton#singleton_method_added: singleton_method_added
metasingleton#singleton_method_added: singleton_method_added
metametasingleton#singleton_method_added: singleton_method_added
--- -- --- ! --- -- ---
Foo#method_added: instance_method
Foo#singleton_method_added: singleton_method
Foo#singleton_method_added: instance_method_on_singleton
singleton#singleton_method_added: singleton_method_on_singleton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment