Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/git_hub/extensions.rb
Instance Method Summary collapse
-
#to_class ⇒ Object
Turns string into appropriate class constant, returns nil if class not found.
Instance Method Details
#to_class ⇒ Object
Turns string into appropriate class constant, returns nil if class not found
3 4 5 6 7 8 9 10 |
# File 'lib/git_hub/extensions.rb', line 3 def to_class klass = self.split("::").inject(Kernel) do |namespace, const| const == '' ? namespace : namespace.const_get(const) end klass.is_a?(Class) ? klass : nil rescue NameError nil end |