Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/sixarm_ruby_string_to_class.rb
Instance Method Summary (collapse)
-
- (Class) to_class
Ruby String#to_class method to convert from a String to a class.
Instance Method Details
- (Class) to_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 |