Tbpgr Blog

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

Ruby | Module | remove_class_variable

概要

Module#remove_class_variable(name) -> object

詳細

引数で指定したクラス変数を取り除き、そのクラス変数に設定されていた値を返却。

サンプルコード
class Hoge
  @@class_variable = 'hoge'
  p @@class_variable
  p remove_class_variable(:@@class_variable)

  begin
    p @@class_variable
  rescue => e
    p e.message
  end
end

出力

出力

"hoge"
"hoge"
"uninitialized class variable @@class_variable in Hoge"