別のキーワード
種類
- インスタンスメソッド (96)
- モジュール関数 (24)
- 関数 (12)
- 文書 (12)
ライブラリ
- ビルトイン (120)
クラス
-
Enumerator
:: Lazy (48) - Object (48)
モジュール
- Kernel (24)
キーワード
-
enum
_ for (48) - iterator? (12)
-
rb
_ f _ block _ given _ p (12) -
to
_ enum (48) - クラス/メソッドの定義 (12)
検索結果
先頭5件
-
Kernel
. # block _ given? -> bool (18119.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 (3019.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... -
クラス/メソッドの定義 (282.0)
-
クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined
...hod
* class_method
* limit
* 定義に関する操作:
* alias
* undef
* defined
===[a:class] クラス定義
//emlist[例][ruby]{
class Foo < Super
def test
# ...
end
# ...
end
//}
文法:
class 識別子 [`<' superclass ]
式..
en......外処理についてはd:spec/control#begin参照。
クラス定義は、識別子で指定した定数へのクラスの代入になります
(Ruby では、クラスもオブジェクトの一つで Classクラスの
インスタンスです)。
クラスが既に定義されているとき、......テレータの定義][ruby]{
# yield を使う
def foo
# block_given? は、メソッドがブロックを渡されて
# 呼ばれたかどうかを判定する組み込み関数
if block_given?
yield(1,2)
end
end
# Proc.new を使う
def bar
if block_given?
Proc.new.call(1,2)... -
static VALUE rb
_ f _ block _ given _ p(void) (32.0) -
block_given? の実体。 現在評価中の (Ruby で実装された) メソッドに対して ブロックが与えられていたら真。
...
block_given? の実体。
現在評価中の (Ruby で実装された) メソッドに対して
ブロックが与えられていたら真。... -
Object
# enum _ for(method = :each , *args) -> Enumerator (18.0) -
Enumerator.new(self, method, *args) を返します。
...。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
module Enumer......able
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 を返す。
sz = size
sz * n if sz
e... -
Object
# enum _ for(method = :each , *args) {|*args| . . . } -> Enumerator (18.0) -
Enumerator.new(self, method, *args) を返します。
...。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
module Enumer......able
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 を返す。
sz = size
sz * n if sz
e... -
Object
# to _ enum(method = :each , *args) -> Enumerator (18.0) -
Enumerator.new(self, method, *args) を返します。
...。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
module Enumer......able
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 を返す。
sz = size
sz * n if sz
e... -
Object
# to _ enum(method = :each , *args) {|*args| . . . } -> Enumerator (18.0) -
Enumerator.new(self, method, *args) を返します。
...。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場合)][ruby]{
module Enumer......able
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 を返す。
sz = size
sz * n if sz
e... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) -> Enumerator :: Lazy (12.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...を返すようになっています。
//emlist[例][ruby]{
module Enumerable
# 要素を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 }...