Class Encoding
In: encoding.c
Parent: Object

Methods

Public Class methods

Returns the hash of available encoding alias and original encoding name.

  Encoding.aliases
  => {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1986"=>"US-ASCII",
      "SJIS"=>"Shift_JIS", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J"}

Checks the compatibility of two strings. If they are compatible, means concatenatable, returns an encoding which the concatinated string will be. If they are not compatible, nil is returned.

  Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b")
  => #<Encoding:ISO-8859-1>

  Encoding.compatible?(
    "\xa1".force_encoding("iso-8859-1"),
    "\xa1\xa1".force_encoding("euc-jp"))
  => nil

Returns default external encoding.

It is initialized by the locale or -E option.

Search the encoding with specified name. name should be a string or symbol.

  Encoding.find("US-ASCII")  => #<Encoding:US-ASCII>
  Encoding.find(:Shift_JIS)  => #<Encoding:Shift_JIS>

Returns the list of loaded encodings.

  Encoding.list
  => [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
      #<Encoding:ISO-2022-JP (dummy)>]

  Encoding.find("US-ASCII")
  => #<Encoding:US-ASCII>

  Encoding.list
  => [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
      #<Encoding:US-ASCII>, #<Encoding:ISO-2022-JP (dummy)>]

Returns the locale charmap name.

  Debian GNU/Linux
    LANG=C
      Encoding.locale_charmap  => "ANSI_X3.4-1968"
    LANG=ja_JP.EUC-JP
      Encoding.locale_charmap  => "EUC-JP"

  SunOS 5
    LANG=C
      Encoding.locale_charmap  => "646"
    LANG=ja
      Encoding.locale_charmap  => "eucJP"

Returns the list of available encoding names.

  Encoding.name_list
  => ["US-ASCII", "ASCII-8BIT", "UTF-8",
      "ISO-8859-1", "Shift_JIS", "EUC-JP",
      "Windows-31J",
      "BINARY", "CP932", "eucJP"]

This list doesn‘t include dummy encodings.

Public Instance methods

Returns true for dummy encodings. A dummy encoding is an encoding for which character handling is not properly implemented. It is used for stateful encodings.

  Encoding::ISO_2022_JP.dummy?       #=> true
  Encoding::UTF_8.dummy?             #=> false

Returns a string which represents the encoding for programmers.

  Encoding::UTF_8.inspect       #=> "#<Encoding:UTF-8>"
  Encoding::ISO_2022_JP.inspect #=> "#<Encoding:ISO-2022-JP (dummy)>"

Returns the name of the encoding.

  Encoding::UTF_8.name       => "UTF-8"

Returns the name of the encoding.

  Encoding::UTF_8.name       => "UTF-8"

[Validate]

ruby-doc.org is a service of James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, AZ.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.