Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

String#upcase

() -> ::String
(:ascii | :lithuanian | :turkic) -> ::String
(:lithuanian, :turkic) -> ::String
(:turkic, :lithuanian) -> ::String
upcase(mapping = :ascii) → new_string

Returns a new string containing the upcased characters in self:

Example
'hello'.upcase        # => "HELLO"
'straße'.upcase       # => "STRASSE"
'привет'.upcase       # => "ПРИВЕТ"
'RubyGems.org'.upcase # => "RUBYGEMS.ORG"

The sizes of self and the upcased result may differ:

Example
s = 'Straße'
s.size        # => 6
s.upcase      # => "STRASSE"
s.upcase.size # => 7

Some characters (and some character sets) do not have upcase and downcase versions; see Case Mapping:

Example
s = '1, 2, 3, ...'
s.upcase == s # => true
s = 'こんにちは'
s.upcase == s # => true

The casing is affected by the given mapping, which may be :ascii, :fold, or :turkic; see Case Mappings.

Related: see Converting to New String.

Ruby version changes

  1. 3.0
See also #upcase! #unpack1 #unpack #upto also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0