Tbpgr Blog

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

Ruby | Object | methods

概要

Object#methods(include_inherited = true) -> [Symbol]

詳細

オブジェクトから呼び出し可能なメソッドの配列を返却。
public, protected のメソッドが対象。

サンプルコード
class Hoge
  def public_hoge; end
  protected
  def protected_hoge; end
  private
  def private_hoge; end
end

print Hoge.new.methods.grep /hoge/

出力

$ ruby object_methods.rb
[:public_hoge, :protected_hoge]