Sha256: b33efcbedfafb8582a8177d98f659c3213f91d2859d8803fed597036c49d264a

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

require 'facet/module/instance_methods'

class Object

  # 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

9 entries across 9 versions & 1 rubygems

Version Path
facets-1.0.3 packages/core/lib/facet/kernel/methods.rb
facets-1.0.0 lib/facet/kernel/methods.rb
facets-1.2.1 lib/facets/core/kernel/methods.rb
facets-1.3.0 lib/facets/core/kernel/methods.rb
facets-1.1.0 lib/facet/kernel/methods.rb
facets-1.2.0 lib/facets/core/kernel/methods.rb
facets-1.3.1 lib/facets/core/kernel/methods.rb
facets-1.3.2 lib/facets/core/kernel/methods.rb
facets-1.3.3 lib/facets/core/kernel/methods.rb