Skip to content

Instantly share code, notes, and snippets.

@murajun1978
Created May 14, 2014 13:04
Show Gist options
  • Save murajun1978/88169357ed5bcaa4f4fe to your computer and use it in GitHub Desktop.
Save murajun1978/88169357ed5bcaa4f4fe to your computer and use it in GitHub Desktop.
module Foo
def foo
:foo
end
end
class Bar
include Foo
def bar
:bar
end
end
class Buz
extend Foo
def buz
:buz
end
end
# Bar Instance methods
p Bar.new.class.instance_methods.grep(/bar|foo/) # => [:bar, :foo]
# Buz Instance methods
p Buz.new.class.instance_methods.grep(/buz|foo/) # => [:buz]
# Buz Class methods
p Buz.new.class.methods.grep(/foo|buz/) # => [:foo]
# a list of modules and classes
p Bar.ancestors # => [Bar, Foo, Object, Kernel, BasicObject]
# singleton methods
p Bar.singleton_methods # => []
# a list of modules and classes
p Buz.ancestors # => [Buz, Object, Kernel, BasicObject]
# singleton methods
p Buz.singleton_methods # => [:foo]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment