Tbpgr Blog

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

メタプログラミングRuby | 文字列クラス

概要

文字列クラス

内容

クラス名文字列からクラスのインスタンスを取得します。
クラス名からクラスを取得する場合はObject.const_getを利用します。

サンプル

# encoding: utf-8

class Hoge
  def hoge
    puts "hoge"
  end
end

hoge = Object.const_get("Hoge").new
hoge.hoge

出力

hoge