Sha256: 888121665614b8de0eade73956d140e66c0b3b81181d2c4985ec1621a8e15735

Contents?: true

Size: 1.21 KB

Versions: 21

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8

# Object
class Object
  # grep public instance method
  #
  # === Example
  #
  # target class
  #
  #   class GrepInstanceMethod
  #     def public_method1;end
  #     def public_method2;end
  #     def public_method11;end
  #     protected
  #     def protected_method1;end
  #     def protected_method2;end
  #     def protected_method11;end
  #     private
  #     def private_method1;end
  #     def private_method2;end
  #     def private_method11;end
  #   end
  #
  #  method call
  #
  #   GrepInstanceMethod.new.grep_public_instance_method :public_method1, false # => [:public_method1]
  #   GrepInstanceMethod.new.grep_public_instance_method /public_method1/, false # => [:public_method1, :public_method11]
  #   GrepInstanceMethod.new.grep_public_instance_method /public_method3/, false # => []
  #   GrepInstanceMethod.new.grep_public_instance_method :equal?, true # => [:equal?]
  #

  %w(public protected private).each do |scope|
    define_method :"grep_#{scope}_instance_method" do |search, all = true|
      search = search.to_sym unless search.is_a? Regexp
      each_methods = send :"#{scope}_methods", all
      each_methods.grep search
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.150 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.149 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.148 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.147 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.146 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.145 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.144 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.143 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.142 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.141 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.140 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.139 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.138 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.137 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.136 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.135 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.134 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.133 lib/open_classes/object/grep_instance_method.rb
tbpgr_utils-0.0.132 lib/open_classes/object/grep_instance_method.rb