Sha256: 164b01fed645b875423558425ae22fa5dad8f3cfeb1a14e7ed48af545602add4

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

require 'fspath'

class Integer
  def minutes
    60 * self
  end
  alias_method :minute, :minutes

  def hours
    60 * minutes
  end
  alias_method :hour, :hours

  def days
    24 * hours
  end
  alias_method :day, :days

  def weeks
    7 * days
  end
  alias_method :week, :weeks
end

class String
  def underscore
    split(/::/).map{ |part| part.split(/(?=[A-Z])/).join('_') }.join('/').downcase
  end
end

class Module
  def smart_autoload(*names)
    names.each do |name|
      autoload name, "#{self}::#{name}".underscore
    end
  end

  def abstract_method(*names)
    names.each do |name|
      class_eval <<-RUBY, __FILE__, __LINE__
        def #{name}(*_)
          raise NotImplementedError.new("\#{self.class.name} has no implementation for method `#{name}`")
        end
      RUBY
    end
  end
end

class Array
  def select!(&block)
    replace(select(&block))
  end
end

class FSPath
  def touch(atime = nil, mtime = nil)
    open('w'){} unless exist?
    utime(atime ||= Time.now, mtime || atime)
  end

  def rmtree_verbose
    require 'fileutils'
    FileUtils.rm_r(@path, :verbose => true)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
doc-0.5.0 lib/doc/core_ext.rb
doc-0.4.1 lib/doc/core_ext.rb
doc-0.4.0 lib/doc/core_ext.rb
doc-0.3.0 lib/doc/core_ext.rb
doc-0.2.8 lib/doc/core_ext.rb
doc-0.2.7 lib/doc/core_ext.rb
doc-0.2.6 lib/doc/core_ext.rb
doc-0.2.5 lib/doc/core_ext.rb
doc-0.2.4 lib/doc/core_ext.rb
doc-0.2.3 lib/doc/core_ext.rb
doc-0.2.2 lib/doc/core_ext.rb