るりまサーチ

最速Rubyリファレンスマニュアル検索!
352件ヒット [1-100件を表示] (0.088秒)

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

ライブラリ

クラス

キーワード

検索結果

<< 1 2 3 ... > >>

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

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

...の要素をひとつ取り除き、
[key, value]という配列として返します。

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

Ruby
3.2以前は、ハッシュが空の場合、デフォルト値(Hash#defaultまた...
...

//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 #=> "d...
...efault value"

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


@see Array#shift...
...

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...

Array#shift -> object | nil (18327.0)

配列の先頭の要素を取り除いてそれを返します。 引数を指定した場合はその個数だけ取り除き、それを配列で返します。

...@raise ArgumentError 引数に負の数を指定した場合に発生します。



//emlist[例][ruby]{
a = [0, 1, 2, 3, 4]
p a.shift #=> 0
p a #=> [1, 2, 3, 4]

p [].shift #=> nil
p [].shift(1) #=> []
//}

@see Array#push, Array#pop, Array#unshift...

Thread::Queue#shift(non_block = false) -> object (15314.0)

キューからひとつ値を取り出します。キューが空の時、呼出元のスレッドは停止します。

...します。キューが空の時、呼出元のスレッドは停止します。

@param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。

//emlist[例][ruby]{
require 'thread'

q = Queue.new

th1 = Thread.start do
while resource = q.pop
puts r...
...|r|
q.push(r)
}

th1.join
//}

//emlist[例: nonblock = true][ruby]{
require 'thread'

q = Queue.new

th1 = Thread.start do
while resource = q.pop
puts resource
end
end

[:resource1, :resource2, :resource3, nil].each { |r|
q.push(r)
}

b
egin
th1.join
q.pop(true)
rescue => e
p e
en...

Thread::SizedQueue#shift(non_block = false) -> object (15314.0)

キューからひとつ値を取り出します。 キューに push しようと待っているスレッドがあれば、実行を再開させます。

...ようと待っているスレッドがあれば、実行を再開させます。

@param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。

//emlist[例][ruby]{
require 'thread'

q = SizedQueue.new(4)

th1 = Thread.start do
while resource = q.pop...
...1
# resource2
# resource3
//}

//emlist[例: nonblock = true][ruby]{
require 'thread'

q = SizedQueue.new(4)

th1 = Thread.start do
while resource = q.pop
puts resource
end
end

[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}

b
egin
th1.join
q.pop(true)
rescue => e
p e...

OpenSSL::BN#lshift!(n) -> self (9207.0)

自身を n ビット左シフトします。 OpenSSL::BN#<<と異なり、破壊的メソッドです。

...す。
OpenSSL::BN#<<と異なり、破壊的メソッドです。

//emlist[][ruby]{
require 'openssl'

b
n = 1.to_bn
b
n.lshift!(2) # => #<OpenSSL::BN 4>
b
n # => #<OpenSSL::BN 4>
//}

@param n シフトするビット数
@raise OpenSSL::BNError 計算時エラー
@see OpenSSL::BN#<<...

絞り込み条件を変える

OpenSSL::BN#rshift!(n) -> self (9207.0)

自身を n ビット右シフトします。 [[m:OpenSSL::BN#>>]と異なり、破壊的メソッドです。

...[[m:OpenSSL::BN#>>]と異なり、破壊的メソッドです。

//emlist[][ruby]{
require 'openssl'

b
n = 8.to_bn
b
n.rshift!(1) # => #<OpenSSL::BN 4>
b
n # => #<OpenSSL::BN 4>
//}

@param n シフトするビット数
@raise OpenSSL::BNError 計算時エラー
@see OpenSSL::BN#>>...

Array#unshift(*obj) -> self (6313.0)

指定された obj を引数の最後から順番に配列の先頭に挿入します。 引数を指定しなければ何もしません。

...obj を引数の最後から順番に配列の先頭に挿入します。
引数を指定しなければ何もしません。

@param obj 自身に追加したいオブジェクトを指定します。

//emlist[例][ruby]{
arr = [1,2,3]
arr.unshift 0
p arr #=> [0, 1, 2, 3]
arr.unshift...
...[0]
p arr #=> [[0], 0, 1, 2, 3]
arr.unshift 1, 2
p arr #=> [1, 2, [0], 0, 1, 2, 3]
//}

@see Array#push, Array#pop, Array#shift...

String#iseuc -> bool (235.0)

self が EUC-JP なバイト列として正当であるかどうかを判定します。

...EUC-JP なバイト列として正当であるかどうかを判定します。

Kconv.#iseuc(self) と同じです。

//emlist[例][ruby]{
require 'kconv'

euc_str = "\
\xa5\xaa\xa5\xd6\xa5\xb8\xa5\xa7\xa5\xaf\xa5\xc8\xbb\xd8\xb8\xfe\
\xa5\xd7\xa5\xed\xa5\xb0\xa5\xe9\xa5\xdf\xa5\xf3\xa5\xb0\xb8\x...
...c0\xb8\xec\
\x52\x75\x62\x79".force_encoding('EUC-JP')

sjis_str = "\
\x83\x49\x83\x75\x83\x57\x83\x46\x83\x4e\x83\x67\x8e\x77\x8c\xfc\
\x83\x76\x83\x8d\x83\x4f\x83\x89\x83\x7e\x83\x93\x83\x4f\x8c\xbe\x8c\xea\
\x52\x75\x62\x79".force_encoding('Shift_JIS')

euc_str.iseuc # => true
sjis_str.iseuc # =...

CSV#return_headers? -> bool (219.0)

ヘッダを返す場合は、真を返します。 そうでない場合は、偽を返します。

...ます。
そうでない場合は、偽を返します。

//emlist[例][ruby]{
require "csv"

csv = CSV.new("header1,header2\nrow1_1,row1_2", headers: true, return_headers: false)
csv.return_headers? # => false
csv.shift # => #<CSV::Row "header1":"row1_1" "header2":"row1_2">

csv = CSV.new("header...
...1,header2\nrow1_1,row1_2", headers: true, return_headers: true)
csv.return_headers? # => true
csv.shift # => #<CSV::Row "header1":"header1" "header2":"header2">
//}

@see CSV.new...
<< 1 2 3 ... > >>