Sha256: 79a13c138c19bad3485d0eb874fc271d4a4ca876e8d73da750fc20fac0c87e9f

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

require 'pathname'

class Hash

  def to_symbolized_hash
    new_hash= {}
    self.each {|k,v| new_hash[k.to_sym]= v }
    new_hash
  end

  def to_hash_object
    Gumdrop::Util::HashObject.from self, true
  end

  def ends_with?(string)
    self[0..(string.length)] == string
  end

  def starts_with?(string)
    self[0..(string.length)] == string
  end

end

class String
  
  def / (other)
    File.join self, other
  end

  def relative
    dup.relative!
  end

  def relative!
    sub! /^[\/]/, ''
    self
  end

  def expand_path(relative_to=nil)
    if (Pathname.new self).absolute?
      self
    elsif relative_to.nil?
      File.expand_path self
    else
      File.expand_path relative_to / self
    end
  end

  def path_match?(pattern)
    File.fnmatch pattern, self, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_CASEFOLD
  end

  # alias_method :starts_with?, :start_with?
  # alias_method :ends_with?, :end_with?

end


# module PathTools

#   def / (other)
#     self.join other.to_s
#   end

#   def - (other)
#     Pathname.new self.to_s.gsub(other, '')
#   end

#   def match?(other)
#     fnmatch? pattern, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_CASEFOLD
#   end

# end

# class Pathname
#   include PathTools
# end

# class String
#   def to_pathname
#     Pathname.new self
#   end
# end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gumdrop-1.1.3 lib/gumdrop/util/core_ex.rb
gumdrop-1.1.2 lib/gumdrop/util/core_ex.rb
gumdrop-1.1.1 lib/gumdrop/util/core_ex.rb
gumdrop-1.1.0 lib/gumdrop/util/core_ex.rb
gumdrop-1.0.3 lib/gumdrop/util/core_ex.rb