種類
- インスタンスメソッド (205)
- モジュール関数 (22)
- 文書 (11)
- ライブラリ (11)
クラス
- Enumerator (22)
- Hash (56)
- Matrix (44)
-
Prime
:: PseudoPrimeGenerator (44)
モジュール
- Enumerable (39)
- Syslog (22)
キーワード
- filter! (12)
-
keep
_ if (22) - mask (11)
- mask= (11)
-
net
/ pop (11) -
ruby 1
. 6 feature (11) - select! (22)
-
to
_ h (17) -
with
_ index (44)
検索結果
先頭5件
-
Prime
:: PseudoPrimeGenerator # with _ index {|prime , index| . . . } -> self (6016.0) -
与えられたブロックに対して、素数を0起点の連番を渡して評価します。
...を返します。 ブロックを与えられなかった場合は Enumerator を返します。
//emlist[例][ruby]{
require 'prime'
Prime::EratosthenesGenerator.new(10).each_with_index do |prime, index|
p [prime, index]
end
# [2, 0]
# [3, 1]
# [5, 2]
# [7, 3]
//}
@see Enumerator#with_index... -
ruby 1
. 6 feature (54.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...-03-10 メソッドの戻り値
以下のメソッドの戻り値が正しくなりました。((<ruby-bugs-ja:PR#205>))
* ((<Enumerable/each_with_index>)) が self を返すようになった(以前は nil)
* ((<Process/Process.setpgrp>)) が返す値が不定だった。
* ((<String/ljus......返すようになった(以前は false)
* IO#close がクローズ済みな IO に対して IOError を起こすようになった。
* IO#each_byte が self を返すようになった(以前は nil)
: rb_define_module_under()
C 関数 rb_define_module_under() でモジュールを定......が Segmentation Fault していました。((<ruby-dev:14942>))
Module.constants.each {|c|
c = eval c
if c.instance_of?(Class)
p c
c.instance_methods.each {|m|
c.module_eval "undef #{m};"
}
c.module_eval {und... -
net
/ pop (48.0) -
このライブラリは、POP3 (Post Office Protocol version 3) を 用いてPOPサーバからメールを受信する機能を提供するライブラリです。
...p.start('YourAccount', 'YourPassword') # POPのセッションを開始
if pop.mails.empty?
$stderr.puts 'no mail.'
else
pop.mails.each_with_index do |m, idx| # 各メッセージにアクセスする
File.open("inbox/#{idx + 1}", 'w') {|f|
f.write m.pop
}
m.de......消したりする
ことができます。Net::POP3#mails はこの Net::POPMail オブジェクトの配列であり、
Net::POP3#each_mail はさらに pop.mails.each のショートカットです。
==== 短くする
上の例はあえて省略や短縮用メソッドを避けたためにか......lse
pop.mails.each_with_index do |m, idx|
File.open("inbox/#{idx + 1}", 'w') {|f|
f.write m.pop
}
m.delete
end
$stderr.puts "#{pop.mails.size} mails popped."
end
}
Net::POP3#delete_all を使うと
さらに Net::POP3#each_mail と
Net::POPM... -
Enumerator
# with _ index(offset = 0) -> Enumerator (24.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
...mlist[例][ruby]{
str = "xyz"
enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]
require "stringio"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["foo|", 1]......にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。... -
Enumerator
# with _ index(offset = 0) {|(*args) , idx| . . . } -> object (24.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
...mlist[例][ruby]{
str = "xyz"
enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]
require "stringio"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["foo|", 1]......にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。... -
Enumerable
# to _ h(*args) -> Hash (18.0) -
self を [key, value] のペアの配列として解析した結果を Hash にして 返します。
...self を [key, value] のペアの配列として解析した結果を Hash にして
返します。
@param args each の呼び出し時に引数として渡されます。
//emlist[例][ruby]{
%i[hello world].each_with_index.to_h # => {:hello => 0, :world => 1}
//}......のペアの配列として解析した結果を Hash にして
返します。
@param args each の呼び出し時に引数として渡されます。
//emlist[例][ruby]{
%i[hello world].each_with_index.to_h # => {:hello => 0, :world => 1}
//}
ブロックを指定すると各要素でブロ... -
Enumerable
# to _ h(*args) { . . . } -> Hash (18.0) -
self を [key, value] のペアの配列として解析した結果を Hash にして 返します。
...のペアの配列として解析した結果を Hash にして
返します。
@param args each の呼び出し時に引数として渡されます。
//emlist[例][ruby]{
%i[hello world].each_with_index.to_h # => {:hello => 0, :world => 1}
//}
ブロックを指定すると各要素でブロ... -
Hash
# filter! -> Enumerator (12.0) -
キーと値を引数としてブロックを評価した結果が真であるような要素を self に残します。
...合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。
//emlist[例][ruby]{
h1 = {}
c = ("a".."g")
c.each_with_index {|e, i| h1[i] = e }
h2 = h1.dup
h1.select! # => #<Enumerator: {0=>"a", 1=>"b", 2=>"c", 3=>"d", 4=>"e", 5=>"f", 6=>"g"}:select!>
h1.select! {... -
Hash
# filter! {|key , value| . . . } -> self | nil (12.0) -
キーと値を引数としてブロックを評価した結果が真であるような要素を self に残します。
...合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。
//emlist[例][ruby]{
h1 = {}
c = ("a".."g")
c.each_with_index {|e, i| h1[i] = e }
h2 = h1.dup
h1.select! # => #<Enumerator: {0=>"a", 1=>"b", 2=>"c", 3=>"d", 4=>"e", 5=>"f", 6=>"g"}:select!>
h1.select! {... -
Hash
# keep _ if -> Enumerator (12.0) -
キーと値を引数としてブロックを評価した結果が真であるような要素を self に残します。
...合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。
//emlist[例][ruby]{
h1 = {}
c = ("a".."g")
c.each_with_index {|e, i| h1[i] = e }
h2 = h1.dup
h1.select! # => #<Enumerator: {0=>"a", 1=>"b", 2=>"c", 3=>"d", 4=>"e", 5=>"f", 6=>"g"}:select!>
h1.select! {... -
Hash
# keep _ if {|key , value| . . . } -> self (12.0) -
キーと値を引数としてブロックを評価した結果が真であるような要素を self に残します。
...合は、自身と keep_if から生成した
Enumerator オブジェクトを返します。
//emlist[例][ruby]{
h1 = {}
c = ("a".."g")
c.each_with_index {|e, i| h1[i] = e }
h2 = h1.dup
h1.select! # => #<Enumerator: {0=>"a", 1=>"b", 2=>"c", 3=>"d", 4=>"e", 5=>"f", 6=>"g"}:select!>
h1.select! {...