Tbpgr Blog

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

Ruby | Module | include?

概要

include?(mod) -> bool

詳細

self かその親クラス / 親モジュールがモジュール mod を インクルードしていれば true を返却。

サンプルコード
require 'tbpgr_utils'

module Hogeable;end

class Hoge
  include Hogeable
end

class Hige
end

bulk_puts_eval binding, <<-EOS
Hoge.include? Hogeable
Hige.include? Hogeable
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

出力

Hoge.include? Hogeable # => true
Hige.include? Hogeable # => false