以下の内容はhttps://tbpgr.hatenablog.com/entry/20141003/1412342022より取得しました。


Ruby | Object | protected_methods

概要

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

詳細

protected メソッド名の一覧を返却。
include_inherited に false を指定すると自クラスのメソッドのみを返却

サンプルコード
require 'tbpgr_utils'

module Mod
  protected
  def mod; end
end

class Parent
  protected
  def parent;end
end

class Child < Parent
  include Mod
  protected
  def child;end
end

child = Child.new
bulk_puts_eval binding, <<-EOS
child.protected_methods.first(5)
child.protected_methods(false).first(5)
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

$ ruby protected_methods.rb
child.protected_methods.first(5)        # => [:child, :mod, :parent]
child.protected_methods(false).first(5) # => [:child]



以上の内容はhttps://tbpgr.hatenablog.com/entry/20141003/1412342022より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14