168件ヒット
[1-100件を表示]
(0.070秒)
別のキーワード
ライブラリ
- ビルトイン (168)
クラス
-
Enumerator
:: Lazy (48) -
Enumerator
:: Yielder (12) - Exception (12)
- Object (48)
- Proc (48)
検索結果
先頭5件
-
Proc
# yield(*arg) -> () (15108.0) -
手続きオブジェクトを実行してその結果を返します。
...きを渡せるようにするためのものです。
//emlist[例][ruby]{
def sign(n)
case n
when lambda{|n| n > 0} then 1
when lambda{|n| n < 0} then -1
else 0
end
end
p sign(-4) #=> -1
p sign(0) #=> 0
p sign(7) #=> 1
//}
また、以下のような syntactic sugar もあります... -
Enumerator
:: Yielder # <<(object) -> () (9101.0) -
Enumerator.new で使うメソッドです。
...ator::Yielder オブジェクトが渡されたブロックが実行され、
ブロック内の << が呼ばれるたびに each に渡されたブロックが
<< に渡された値とともに繰り返されます。
//emlist[例][ruby]{
enum = Enumerator.new do |y|
y << 1
y << 2
y << 3
end... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) -> Enumerator :: Lazy (13.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...繰り返すメソッド
# 例:[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}.repeat(2).first... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (13.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...繰り返すメソッド
# 例:[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}.repeat(2).first... -
Enumerator
:: Lazy # to _ enum(method = :each , *args) -> Enumerator :: Lazy (13.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...繰り返すメソッド
# 例:[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}.repeat(2).first... -
Enumerator
:: Lazy # to _ enum(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (13.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
...繰り返すメソッド
# 例:[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}.repeat(2).first... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (13.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
...def get_exception
return begin
yield
rescue => e
e
end
end
e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_exception'", "test.rb:15:in `<main>'"]
//}
@see Exception#back... -
Object
# enum _ for(method = :each , *args) -> Enumerator (13.0) -
Enumerator.new(self, method, *args) を返します。
...s 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__ はここでは......ize
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 4... -
Object
# enum _ for(method = :each , *args) {|*args| . . . } -> Enumerator (13.0) -
Enumerator.new(self, method, *args) を返します。
...s 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__ はここでは......ize
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 4...