Tbpgr Blog

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

Ruby | Module | nesting

概要

Module.nesting -> [Class, Module]

詳細

このメソッドを呼び出した時点でのクラス/モジュールのネスト情報を配列で返却

サンプルコード
require 'tbpgr_utils'require 'tbpgr_utils'

module HogeModule
  class HogeClass
    def hoge
      Module.nesting
    end
  end
end

h = HogeModule::HogeClass.new

bulk_puts_eval binding, <<-EOS
Module.nesting
h.hoge
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

Module.nesting # => []
h.hoge         # => [HogeModule::HogeClass, HogeModule]