Sha256: 166ca6976307020d16ea2b74ad6de1e7bb638217ae43de09df2a61c1f455d604

Contents?: true

Size: 828 Bytes

Versions: 2

Compression:

Stored size: 828 Bytes

Contents

# Converts a number into an ordinal, 1=>1st, 2=>2nd, 3=>3rd, etc
class Fixnum
  def ordinal
    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

# Avoid a collision with ActiveSupport
class Date
  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

class String
  # Support String::bytesize in old versions of Ruby
  if RUBY_VERSION < "1.9"
    def bytesize
      size
    end
  end
  
  # Capitalize the first letter of each word in a string
  def titleize     
    self.split(/(\W)/).map(&:capitalize).join       
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
baron-1.0.12 lib/baron/utils.rb
baron-1.0.11 lib/baron/utils.rb