Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created September 30, 2014 01:51
Show Gist options
  • Save elskwid/5eacff66d5dd10de0853 to your computer and use it in GitHub Desktop.
Save elskwid/5eacff66d5dd10de0853 to your computer and use it in GitHub Desktop.
extended methods don't play nice
module A
def a_method
puts "a method"
end
end
# => :a_method
class B
extend A
def b_method
puts "b method"
end
def self.c_method
puts "c_method"
end
end
# => :c_method
B.singleton_methods
# => [:c_method, :a_method]
B.a_method
# a method
# => nil
B.c_method
# c_method
# => nil
B.singleton_methods(:all).select { |sm| begin; B.singleton_method(sm); false; rescue; true; end }
# => [:a_method]
B.singleton_method(:c_method)
# => #<Method: B.c_method>
B.singleton_method(:a_method)
# NameError: undefined singleton method `a_method' for `B'
# from (pry):30:in `singleton_method'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment