Sha256: dec93acac7fe7647ef6d20a444809c8b12ebf613e5f84a28a52fbc6a45889011

Contents?: true

Size: 1.34 KB

Versions: 22

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8

# Object
class Object
  def self.grep_method(search, all = true)
    search = search.to_sym unless search.is_a? Regexp
    methods(all).grep search
  end

  # grep public instance method
  #
  # === Example
  #
  # target class
  #
  #   class GrepMethod
  #     def self.public_method1;end
  #     def self.public_method2;end
  #     def self.public_method11;end
  #     protected
  #     def self.protected_method1;end
  #     def self.protected_method2;end
  #     def self.protected_method11;end
  #     private
  #     def self.private_method1;end
  #     def self.private_method2;end
  #     def self.private_method11;end
  #   end
  #
  #  method call
  #
  #   GrepMethod.new.grep_method :public_method1, false # => [:public_method1]
  #   GrepMethod.grep_method :public_method1, false # => [:public_method1]
  #   GrepMethod.new.grep_method /public_method1/, false # => [:public_method1, :public_method11]
  #   GrepMethod.grep_method /public_method1/, false # => [:public_method1, :public_method11]
  #   GrepMethod.new.grep_method /public_method3/, false # => []
  #   GrepMethod.grep_method /public_method3/, false # => []
  #   GrepMethod.new.grep_method :__send__, true # => [:__send__]
  #   GrepMethod.grep_method :__send__, true # => [:__send__]
  #
  def grep_method(search, all = true)
    self.class.grep_method(search, all)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.131 lib/open_classes/object/grep_method.rb
tbpgr_utils-0.0.130 lib/open_classes/object/grep_method.rb