Tbpgr Blog

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

Ruby | Module | included_modules

概要

Module#included_modules -> [Module]

詳細

self にインクルードされているモジュールの配列を返却。

サンプルコード
require 'tbpgr_utils'

module Hogeable;end
module Higeable;end

class Hoge
  include Hogeable
  include Higeable
end

class Hige
end

bulk_puts_eval binding, <<-EOS
Hoge.included_modules
Hige.included_modules
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

出力

Hoge.included_modules # => [Higeable, Hogeable, Kernel]
Hige.included_modules # => [Kernel]