Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Module | instance_methods

概要

Module#instance_methods(inherited_too = true) -> [Symbol]

詳細

そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返却。

サンプルコード
require 'tbpgr_utils'

module Hogeable
  def hogeable
  end
end

class Hoge
  include Hogeable
  def hoge
    print 'hoge'
  end
end

bulk_puts_eval binding, <<-EOS
Hoge.instance_methods.first(5)
Hoge.instance_methods(false)
EOS


__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

出力

Hoge.instance_methods.first(5) # => [:hoge, :hogeable, :any_of?, :boolean?, :grep_method]
Hoge.instance_methods(false)   # => [:hoge]