Sha256: 28588a102ceef7680e6a625e866a2e59de4357e7752b4db443e81a217f5d6ccc

Contents?: true

Size: 327 Bytes

Versions: 2

Compression:

Stored size: 327 Bytes

Contents

class String
  # Turns string into appropriate class constant, returns nil if class not found
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
my_scripts-0.0.7 lib/my_scripts/extensions.rb
my_scripts-0.0.6 lib/my_scripts/extensions.rb