Method: String#to_class
- Defined in:
- lib/openc3/core_ext/string.rb
#to_class ⇒ Class
Converts a String representing a class (i.e. “MyGreatClass”) to the actual class that has been required and is present in the Ruby runtime.
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/openc3/core_ext/string.rb', line 330 def to_class klass = nil split_self = self.split('::') if split_self.length > 1 split_self.each do |class_name| if klass klass = klass.const_get(class_name) else klass = Object.const_get(class_name) end end else begin klass = OpenC3.const_get(self) rescue begin klass = Object.const_get(self) rescue end end end klass end |