るりまサーチ

最速Rubyリファレンスマニュアル検索!
22件ヒット [1-22件を表示] (0.081秒)
トップページ > クエリ:l[x] > クエリ:Hash[x] > クエリ:>[x] > クエリ:shift[x] > 種類:インスタンスメソッド[x]

別のキーワード

  1. _builtin hash
  2. hash []
  3. matrix hash
  4. dbm to_hash
  5. _builtin to_hash

ライブラリ

クラス

検索結果

Hash#shift -> [object, object] | nil (39368.0)

ハッシュからキーが追加された順で先頭の要素をひとつ取り除き、 [key, value]という配列として返します。

...き、
[key, value]という配列として返します。

shift
は破壊的メソッドです。selfは要素を取り除かれた残りのハッシュに変更されます。

Ruby 3.2以前は、ハッシュが空の場合、デフォルト値(Hash#defaultまたはHash#default_procのブロッ...
...もnilならばnil
を返します(このとき、[key,value] という形式の値を返すわけではないことに注意)。

3.2以降ではデフォルト値に関わらず nil を返すよう変更されています。

//emlist[例][ruby]{
h = {:ab => "some" , :cd => "all"}
p h.shift...
...#=> [:ab, "some"]
p h.shift #=> [:cd, "all"]
p h #=> {}
p h.shift #=> nil

h1 = Hash.new("default value")
p h1 #=> {}
p h1.shift #=> "default value"

h2 = Hash.new {|*arg| arg}
p h2 #=> {}
p h2.shift...
...[key, value]という配列として返します。

shift
は破壊的メソッドです。selfは要素を取り除かれた残りのハッシュに変更されます。


ハッシュが空の場合、デフォルト値に関わらず nil を返します。

//emlist[例][ruby]{
h = {:ab => "some"...
..., :cd => "all"}
p h.shift #=> [:ab, "some"]
p h.shift #=> [:cd, "all"]
p h #=> {}
p h.shift #=> nil

h1 = Hash.new("default value")
p h1 #=> {}
p h1.shift #=> nil

h2 = Hash.new {|*arg| arg}
p h2...
...#=> {}
p h2.shift #=> nil
//}


@see Array#shift...

CGI#header(options = "text/html") -> String (225.0)

HTTP ヘッダを options に従って生成します。 CGI#out と違い、標準出力には出力しません。 CGI#out を使わずに自力で HTML を出力したい場合などに使います。 このメソッドは文字列エンコーディングを変換しません。

...ずに自力で HTML を出力したい場合などに使います。
このメソッドは文字列エンコーディングを変換しません。

ヘッダのキーとしては以下が利用可能です。

: type
Content-Type ヘッダです。デフォルトは "text/html" です。
: chars...
...ます。Connection ヘッダに対応します。
: length
送信するコンテンツの長さを指定します。Content-Length ヘッダに対応します。
: language
送信するコンテンツの言語を指定します。Content-Language ヘッダに対応します。
: expires
...
...--> "200 OK"
"PARTIAL_CONTENT" --> "206 Partial Content"
"MULTIPLE_CHOICES" --> "300 Multiple Choices"
"MOVED" --> "301 Moved Permanently"
"REDIRECT" --> "302 Found"
"NOT_MODIFIED" --> "304 Not Modified"...