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


Ruby | Module | class_variable_get

概要

Module#class_variable_get(name) -> bool

詳細

クラス/モジュールに定義されているクラス変数 name の値を返却。

サンプルコード
require 'tbpgr_utils'

module Hogeable
  @@hoge = 1
end

class Hoge
  @@hoge = 2
end

class Hige
  include Hogeable
end

bulk_puts_eval binding, <<-EOS
Hoge.class_variable_get :@@hoge
Hige.class_variable_get :@@hoge
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

出力

Hoge.class_variable_get :@@hoge # => 2
Hige.class_variable_get :@@hoge # => 1



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

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