Sha256: 1708beff87e64b216492fe9b3ff4adecec423b2a247634bf3058e1d239ff2ea1

Contents?: true

Size: 664 Bytes

Versions: 1

Compression:

Stored size: 664 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

class Array

  # Splits (arguments) Array into two components: enum for args and options Hash
  # options Hash (if any) should be the last component of Array
  def args_and_opts 
      opts = self.last
      if opts.is_a?(Hash)
        [self[0..-2].to_enum, opts]
      else
        [self.to_enum, {}]
      end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_hub-0.3.0 lib/git_hub/extensions.rb