On Fri, Apr 18, 2008 at 10:46 AM, Rob Kaufman <[EMAIL PROTECTED]> wrote:
> Its worth noting that Kevin's method is Ruby, where constantize is Rails
> sugar.
>
> Cheers,
> Rob

Also, I think constantize is implemented like this:

class String
  def constantize
    self.split("::").inject(Object) do |enclosing_class, name_segment|
      enclosing_class.const_get(name_segment)
    end
  end
end

(atleast that's how I'd implement it)

So it actually takes strings that may have namespacing and grabs the
constant properly. Pure `const_get` can't do that.

-- 
Kevin Clark
http://glu.ttono.us

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to