るりまサーチ

最速Rubyリファレンスマニュアル検索!
121件ヒット [1-100件を表示] (0.064秒)
トップページ > クエリ:-[x] > クエリ:block_given?[x]

別のキーワード

  1. socket ip_block_source
  2. socket mcast_block_source
  3. openssl block_size
  4. digest block_length
  5. psych block

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Kernel.#block_given? -> bool (18213.0)

メソッドにブロックが与えられていれば真を返します。

...(ブロックが必ずイテレートするとはいえないので)推奨されていないの
block_given? を使ってください。

//emlist[例][ruby]{
def check
if block_given?
puts "Block is given."
else
puts "Block isn't given."
end
end
check{} #=> Block is given.
ch...

Kernel.#iterator? -> bool (3113.0)

メソッドにブロックが与えられていれば真を返します。

...(ブロックが必ずイテレートするとはいえないので)推奨されていないの
block_given? を使ってください。

//emlist[例][ruby]{
def check
if block_given?
puts "Block is given."
else
puts "Block isn't given."
end
end
check{} #=> Block is given.
ch...

クラス/メソッドの定義 (108.0)

クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined

...い場合は nil を返します。

===[a:method] メソッド定義

//emlist[例][ruby]{
def fact(n)
if n == 1 then
1
else
n * fact(n-1)
end
end
//}

文法:

def メソッド名 ['(' [arg0 ['=' default0]] ... [',' '*' rest_args [, post ...]] [',' key1: [val1]] ... [',' '*...
...を省いてdef foo a, bとも
a + 3 * b
end
//}

メソッド名としては通常の識別子の他に、再定義可能な演算子(例: ==, +, -
など spec/operator を参照)も指定できます(operator参照)。

//emlist[例][ruby]{
class Vector2D
attr_accessor :x, :y # インスタ...
...# blk: #<Proc:0x007f7e7d8dd6c0@-:16>
//}

//emlist[例: イテレータの定義][ruby]{
# yield を使う
def foo
# block_given? は、メソッドがブロックを渡されて
# 呼ばれたかどうかを判定する組み込み関数
if block_given?
yield(1,2)
end
end

# Proc.n...

Enumerator::Lazy#enum_for(method = :each, *args) -> Enumerator::Lazy (106.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if block_given?
each do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}...

Enumerator::Lazy#enum_for(method = :each, *args) {|*args| block} -> Enumerator::Lazy (106.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if block_given?
each do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}...

絞り込み条件を変える

Enumerator::Lazy#to_enum(method = :each, *args) -> Enumerator::Lazy (106.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if block_given?
each do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}...

Enumerator::Lazy#to_enum(method = :each, *args) {|*args| block} -> Enumerator::Lazy (106.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0
if block_given?
each do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}...

Object#enum_for(method = :each, *args) -> Enumerator (106.0)

Enumerator.new(self, method, *args) を返します。

...(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n...

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (106.0)

Enumerator.new(self, method, *args) を返します。

...(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n...

Object#to_enum(method = :each, *args) -> Enumerator (106.0)

Enumerator.new(self, method, *args) を返します。

...(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n...

絞り込み条件を変える

<< 1 2 > >>