Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/sixarm_ruby_string_to_class.rb
Instance Method Summary collapse
-
#to_class ⇒ Class
Ruby String#to_class method to convert from a String to a class.
Instance Method Details
#to_class ⇒ Class
Ruby String#to_class method to convert from a String to a class
From Mirage at infovore.org/archives/2006/08/02/getting-a-class-object-in-ruby-from-a-string-containing-that-classes-name/
18 19 20 |
# File 'lib/sixarm_ruby_string_to_class.rb', line 18 def to_class split('::').inject(Kernel) {|scope, const_name| scope.const_get(const_name)} end |