<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <generator>Persumi - Level up your writing and blogging with AI</generator>
  <category label="Blog" scheme="http://persumi.com/u/fredwu/tech/e/blog" term="blog"/>
  <category label="Tech" scheme="http://persumi.com/u/fredwu/tech" term="tech"/>
  <link href="http://persumi.com/u/fredwu/tech/e/blog/t/constantize"/>
  <link href="http://persumi.com/u/fredwu/tech/e/blog/t/constantize/feed/rss"/>
  <link rel="self" href="http://persumi.com/u/fredwu/tech/e/blog/t/constantize/feed/atom"/>
  <author>
    <name>Fred Wu</name>
    <email>ifredwu@gmail.com</email>
    <uri>http://persumi.com/u/fredwu</uri>
  </author>
  <subtitle/>
  <id>http://persumi.com/u/fredwu/tech/e/blog/t/constantize</id>
  <title>Blog (constantize) - Fred Wu&apos;s Tech</title>
  <updated>2026-05-01T23:27:30.261845Z</updated>
  <entry>
    <content type="html">&lt;![CDATA[&lt;p&gt;
So we want to dynamically instantiate an object (i.e. convert a string to a class constant).&lt;/p&gt;
&lt;p&gt;
Instead of doing this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;ruby language-ruby&quot;&gt;@dynamic_var = &quot;User&quot;
eval(@dynamic_var)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
You can do this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;ruby language-ruby&quot;&gt;@dynamic_var = &quot;User&quot;
@dynamic_var.constantize&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
See more about the &lt;code class=&quot;inline&quot;&gt;constantize&lt;/code&gt; method in &lt;a href=&quot;http://apidock.com/rails/ActiveSupport/CoreExtensions/String/Inflections/constantize&quot;&gt;Rails’s API&lt;/a&gt;.&lt;/p&gt;
]]&gt;</content>
    <published>2010-02-26T06:33:00.000000Z</published>
    <category label="Blog" scheme="http://persumi.com/u/fredwu/tech/e/blog" term="blog"/>
    <category label="Tech" scheme="http://persumi.com/u/fredwu/tech" term="tech"/>
    <link href="http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-string-constantize"/>
    <author>
      <name>Fred Wu</name>
      <email>ifredwu@gmail.com</email>
      <uri>http://persumi.com/u/fredwu</uri>
    </author>
    <id>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-string-constantize</id>
    <title>[Rails Tip] &quot;String&quot;.constantize</title>
    <updated>2010-02-26T06:33:00.000000Z</updated>
  </entry>
</feed>