Sha256: d8402b937c69d6a8c211532199f235838fda82eb1927a30b5877c70580640899

Contents?: true

Size: 1.98 KB

Versions: 10

Compression:

Stored size: 1.98 KB

Contents

# -*- encoding: UTF-8 -*-
require 'digest/sha1'
require 'csd/vendor/term/ansicolor'
require 'csd/vendor/active_support/inflector'

module CSD
  module Extensions
    module Core
      # This module comprises extensions to String objects.
      #
      module String
        
        # Adds a double-quote to the beginning and the end of a +String+.
        #
        # ==== Example
        #
        #   'Hello World'.enquote    # => '`Hello World´'
        #
        def enquote
          %Q{"#{self}"}
        end
        
        # Creates a SHA1 hash of the String object.
        #
        def hashed
          Digest::SHA1.hexdigest self
        end
        
        # See CSD::Vendor::ActiveSupport::Inflector#constantize
        #
        def constantize
          Vendor::ActiveSupport::Inflector.constantize(self)
        end
        
        # See CSD::Vendor::ActiveSupport::Inflector#camelize
        #
        def camelize
          Vendor::ActiveSupport::Inflector.camelize(self)
        end
        
        # See CSD::Vendor::ActiveSupport::Inflector#demodulize
        #
        def demodulize
          Vendor::ActiveSupport::Inflector.demodulize(self)
        end
        
        # See CSD::Vendor::ActiveSupport::Inflector#underscore. Note that there is
        # a name conflict with <tt>String#underscore</tt> provided by CSD::Vendor::Term::ANSIColor,
        # which is why this method is renamed to +underscorize+.
        # 
        def underscorize
          Vendor::ActiveSupport::Inflector.underscore(self)
        end
        
        # Just an alias to the more logical wording of this method
        #
        def starts_with?(*args) #:nodoc:
          start_with?(*args)
        end
        
        # Just an alias to the more logical wording of this method
        #
        def ends_with?(*args) #:nodoc:
          end_with?(*args)
        end
        
      end
    end
  end
end

class String #:nodoc:
  include CSD::Vendor::Term::ANSIColor
  include CSD::Extensions::Core::String
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
csd-0.4.3 lib/csd/extensions/core/string.rb
csd-0.4.2 lib/csd/extensions/core/string.rb
csd-0.4.1 lib/csd/extensions/core/string.rb
csd-0.4.0 lib/csd/extensions/core/string.rb
csd-0.3.7 lib/csd/extensions/core/string.rb
csd-0.3.6 lib/csd/extensions/core/string.rb
csd-0.3.5 lib/csd/extensions/core/string.rb
csd-0.3.4 lib/csd/extensions/core/string.rb
csd-0.3.3 lib/csd/extensions/core/string.rb
csd-0.3.2 lib/csd/extensions/core/string.rb