Sha256: 55d10d416a1ada20dea8dd382503f21a4690d818c74bbb3a983420a865614823
Contents?: true
Size: 1.59 KB
Versions: 7
Compression:
Stored size: 1.59 KB
Contents
# TITLE: # # String Case Extensions # # SUMMARY: # # String case-related extensions. # # CREDIT: # # - Phil Tomson # - Thomas Sawyer # # TODO: # # - Perhaps add camelcase methods. # class String # CREDIT Phil Tomson # Return true if the string is capitalized, otherwise false. # # "THIS".capitalized? #=> true # "This".capitalized? #=> true # "this".capitalized? #=> false def capitalized? self =~ /^[A-Z]/ end # CREDIT Phil Tomson # Return true if the string is lowercase (downcase), otherwise false. # # "THIS".downcase? #=> false # "This".downcase? #=> false # "this".downcase? #=> true def downcase? downcase == self end # CREDIT Phil Tomson # Is the string upcase/uppercase? # # "THIS".upcase? #=> true # "This".upcase? #=> false # "this".upcase? #=> false def upcase? self.upcase == self end # Alias for #downcase? method. alias_method :lowercase?, :downcase? # Alias for #upcase? method. alias_method :uppercase?, :upcase? end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' #class String # include Compare #end class TestStringCase < Test::Unit::TestCase def test_capitalized? assert( 'Abc'.capitalized? ) end def test_downcase? assert( 'abc'.downcase? ) end def test_lowercase? assert( 'abc'.lowercase? ) end def test_upcase? assert( 'ABC'.upcase? ) end def test_uppercase? assert( 'ABC'.uppercase? ) end end =end
Version data entries
7 entries across 7 versions & 1 rubygems