Sha256: 405044af2652ada0f302058406cd85f867342ad39cee90c90c7ef7b346399695
Contents?: true
Size: 1.64 KB
Versions: 3
Compression:
Stored size: 1.64 KB
Contents
require 'facets/core/module/instance_methods' module Kernel # Returns a list of methods according to symbol(s) given. # # Usable symbols include: # # * <tt>:inherited</tt> or <tt>:ancestors</tt> # * <tt>:local</tt> or <tt>:no_ancestors</tt> # * <tt>:public</tt> # * <tt>:private</tt> # * <tt>:protected</tt> # * <tt>:singleton</tt> # * <tt>:all</tt> # # It no symbol is given then :public is assumed. # Unrecognized symbols raise an error. # # def test # puts("Hello World!") # end # # methods(:local) #=> ['test'] # def methods(*args) args = [ :public, :local, :ancestors ] if args.empty? m = self.class.instance_methods( *args ) m |= singleton_methods if args.include?( :singleton ) or args.include?( :all ) m end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TC_Methods < Test::Unit::TestCase class O def a ; end end $o = O.new # get a hold of the original definition _before require_ $imF = $o.method( :methods ) def test_instance_methods assert_equal( $imF.call.sort, $o.methods ) end def test_public_instance_methods assert_equal( $o.public_methods.sort, $o.methods(:public) ) end def test_private_instance_methods assert_equal( $o.private_methods.sort, $o.methods(:private) ) end def test_protected_instance_methods assert_equal( $o.protected_methods.sort, $o.methods(:protected) ) end def test_local_instance_methods assert_equal( ["a"], $o.methods(:local) ) end end =end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
facets-1.8.49 | lib/facets/core/kernel/methods.rb |
facets-1.8.51 | lib/facets/core/kernel/methods.rb |
facets-1.8.54 | lib/facets/core/kernel/methods.rb |