Taken from a previous post with some changes, to implement the sepp2k comment about namespaces, I implemented the String # to_class method. I am sharing the code here, and I believe that it can be reorganized in some way specifically for the "i" counter. Your comments are appreciated.
class String def to_class chain = self.split "::" i=0 res = chain.inject(Module) do |ans,obj| break if ans.nil? i+=1 klass = ans.const_get(obj)
ruby metaprogramming introspection
khelll Sep 19 '09 at 14:36 2009-09-19 14:36
source share