別のキーワード
種類
- インスタンスメソッド (72)
- モジュール関数 (24)
- 文書 (12)
- 関数 (12)
ライブラリ
- ビルトイン (96)
クラス
-
Enumerator
:: Lazy (24) - Object (48)
モジュール
- Kernel (24)
キーワード
-
enum
_ for (36) - iterator? (12)
-
rb
_ f _ block _ given _ p (12) -
to
_ enum (36) - クラス/メソッドの定義 (12)
検索結果
先頭5件
-
Kernel
. # block _ given? -> bool (24213.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.
check #=> Block isn't given.
//}... -
static VALUE rb
_ f _ block _ given _ p(void) (6116.0) -
block_given? の実体。 現在評価中の (Ruby で実装された) メソッドに対して ブロックが与えられていたら真。
...
block_given? の実体。
現在評価中の (Ruby で実装された) メソッドに対して
ブロックが与えられていたら真。... -
Kernel
. # iterator? -> bool (6113.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.
check #=> Block isn't given.
//}... -
Object
# enum _ for(method = :each , *args) -> Enumerator (3018.0) -
Enumerator.new(self, method, *args) を返します。
...ist[][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 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 を返す。
sz = size
sz * n if sz
end
end... -
Object
# enum _ for(method = :each , *args) {|*args| . . . } -> Enumerator (3018.0) -
Enumerator.new(self, method, *args) を返します。
...ist[][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 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 を返す。
sz = size
sz * n if sz
end
end... -
Object
# to _ enum(method = :each , *args) -> Enumerator (3018.0) -
Enumerator.new(self, method, *args) を返します。
...ist[][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 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 を返す。
sz = size
sz * n if sz
end
end... -
Object
# to _ enum(method = :each , *args) {|*args| . . . } -> Enumerator (3018.0) -
Enumerator.new(self, method, *args) を返します。
...ist[][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 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 を返す。
sz = size
sz * n if sz
end
end... -
クラス/メソッドの定義 (114.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......ure 節を指定し、例外処理ができます。
例外処理についてはd:spec/control#begin参照。
クラス定義は、識別子で指定した定数へのクラスの代入になります
(Ruby では、クラスもオブジェクトの一つで Classクラスの
インスタンスで......# b: "b"
# c: "c"
# m: 2
# n: 3
# rest: ["foo", "bar", "baz"]
# x: "x"
# y: "y"
# z: "z"
# k: 42
# kwrest: {:u=>"unknown"}
# blk: #<Proc:0x007f7e7d8dd6c0@-:16>
//}
//emlist[例: イテレータの定義][ruby]{
# yield を使う
def foo
# block_given?... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (106.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...Object#to_enum と同じですが、Enumerator::Lazy を返します。
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 }...