Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/git_hub/extensions.rb

Instance Method Summary collapse

Instance Method Details

#to_classObject

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