Tbpgr Blog

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

Ruby | Module | remove_const

概要

Module#remove_const(name) -> object

詳細

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

サンプルコード
require 'english'

class Hoge
  HOGE_CONST = 'hoge'
  print constants, "\n"
  remove_const :HOGE_CONST
  print constants, "\n"
end

出力

$ ruby remove_const.rb
[:HOGE_CONST]
[]