Ruby 4.0 リファレンスマニュアル

singleton method URI.decode_uri_component

decode_uri_component(str, enc=Encoding::UTF_8) -> StringRuby 3.2 から[permalink][rdoc][edit]

パーセントエンコードされた文字列 str をデコードした文字列を返します。

URI.decode_www_form_component と同様の変換を行いますが、"+" という文字はデコードせずそのまま残す点が異なります。

enc で指定したエンコーディングの文字列がパーセントエンコードされたものとみなし、返り値にそのエンコーディングを付加します。

[PARAM] str:
デコード対象の文字列です。
[PARAM] enc:
変換先のエンコーディングです。
[EXCEPTION] ArgumentError:
str のパーセントエンコーディングの書式が不正である場合に発生します。
require 'uri'
p URI.decode_uri_component('a+b%20c') # => "a+b c"

[SEE_ALSO] URI.encode_uri_component, URI.decode_www_form_component