Sha256: 1fc502d47284c20c596ee6bef58ada91ebf25dad7195f93dbff4bfaca69ac035

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

class Object
  def meta_def name, &blk
    (class << self; self; end).instance_eval do
      define_method(name, &blk)
    end
  end
end

class String
  def slugize
    self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
  end

  def humanize
    self.capitalize.gsub(/[-_]+/, ' ')
  end
end

class Fixnum
  def ordinal
    # 1 => 1st
    # 2 => 2nd
    # 3 => 3rd
    # ...
    case self % 100
      when 11..13; "#{self}th"
    else
      case self % 10
        when 1; "#{self}st"
        when 2; "#{self}nd"
        when 3; "#{self}rd"
        else    "#{self}th"
      end
    end
  end
end

class Date
  # This check is for people running RubySlippers::Enginewith ActiveSupport, avoid a collision
  unless respond_to? :iso8601
    # Return the date as a String formatted according to ISO 8601.
    def iso8601
      ::Time.utc(year, month, day, 0, 0, 0, 0).iso8601
    end
  end
end

module Kernel
  def silence_stream(stream)
    old_stream = stream.dup
    stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
    stream.sync = true
    yield
  ensure
    stream.reopen(old_stream)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ruby-slippers-0.1.43 lib/ext/ext.rb
ruby-slippers-0.1.40 lib/ext/ext.rb
ruby-slippers-0.1.11 lib/ext/ext.rb
ruby-slippers-0.1.7 lib/ext/ext.rb
ruby-slippers-0.1.2 lib/ext/ext.rb
ruby-slippers-0.1.1 lib/ext/ext.rb
ruby-slippers-0.0.26 lib/ext/ext.rb
ruby-slippers-0.0.25 lib/ext/ext.rb
ruby-slippers-0.0.13 lib/ext/ext.rb
ruby-slippers-0.0.5 lib/ext/ext.rb
ruby-slippers-0.0.1 lib/ext/ext.rb