Sha256: ddfb35b6bd8073fdedcc99ebf69409b078074d98c0b142b5777fc30b01ab8e70

Contents?: true

Size: 895 Bytes

Versions: 5

Compression:

Stored size: 895 Bytes

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 TinMan with 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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tinman-0.5.0 lib/ext/ext.rb
tinman-0.4.0 lib/ext/ext.rb
tinman-0.3.0 lib/ext/ext.rb
tinman-0.2.0 lib/ext/ext.rb
tinman-0.1.0 lib/ext/ext.rb