クラス
-
ARGF
. class (15) - Array (50)
- Binding (1)
- Class (1)
- Complex (10)
- Dir (4)
- Encoding (2)
-
Encoding
:: Converter (6) -
Encoding
:: InvalidByteSequenceError (2) -
Encoding
:: UndefinedConversionError (2) - Enumerator (16)
-
Enumerator
:: ArithmeticSequence (14) -
Enumerator
:: Chain (5) -
Enumerator
:: Lazy (38) -
Enumerator
:: Yielder (3) - Exception (1)
- File (6)
-
File
:: Stat (42) - Float (44)
- Hash (25)
- IO (23)
- Integer (10)
- LoadError (1)
- MatchData (24)
- Method (1)
- Module (18)
- NilClass (4)
- NoMethodError (1)
- Numeric (18)
- Object (9)
- Proc (2)
-
Process
:: Status (15) -
Process
:: Tms (4) - Random (4)
- Range (8)
- Rational (30)
- Regexp (3)
-
RubyVM
:: InstructionSequence (3) - StopIteration (1)
- String (36)
- Struct (5)
- Symbol (2)
- SystemExit (1)
- Thread (6)
-
Thread
:: Backtrace :: Location (7) - Time (6)
- TracePoint (1)
- UnboundMethod (1)
モジュール
- Enumerable (48)
- GC (1)
キーワード
- % (3)
- & (1)
- * (2)
- ** (2)
- + (3)
- - (3)
- -@ (2)
-
/ (2) - < (1)
- << (1)
- <= (1)
- <=> (3)
- == (5)
- === (1)
- > (1)
- >= (1)
- >> (1)
- [] (8)
-
abort
_ on _ exception= (1) - abs (2)
-
absolute
_ path (2) - all? (2)
- allocate (1)
- angle (3)
- any? (2)
-
append
_ features (1) - arg (3)
-
ascii
_ compatible? (1) - atime (2)
- attr (3)
-
attr
_ accessor (1) -
attr
_ reader (1) -
attr
_ writer (1) - autoload (1)
-
backtrace
_ locations (3) -
base
_ label (1) - begin (2)
- birthtime (1)
- blksize (1)
- blockdev? (1)
- blocks (1)
- bsearch (2)
-
bsearch
_ index (1) - bytes (2)
- captures (1)
- ceil (2)
- chain (1)
- chardev? (1)
- chars (2)
- chunk (3)
-
chunk
_ while (2) - codepoints (2)
- coerce (1)
- collect (3)
- collect! (1)
-
collect
_ concat (3) - combination (2)
- concat (4)
- conjugate (2)
-
const
_ source _ location (1) - convert (1)
- convpath (1)
- coredump? (1)
- cstime (1)
- ctime (1)
- cutime (1)
- cycle (2)
-
delete
_ at (1) -
delete
_ if (2) - denominator (5)
-
deprecate
_ constant (1) -
destination
_ encoding (3) -
destination
_ encoding _ name (2) - detect (1)
- dev (1)
-
dev
_ major (1) -
dev
_ minor (1) - directory? (1)
- divmod (1)
- downto (1)
- drop (1)
-
drop
_ while (3) - each (18)
-
each
_ byte (3) -
each
_ char (3) -
each
_ child (1) -
each
_ codepoint (3) -
each
_ cons (1) -
each
_ entry (1) -
each
_ grapheme _ cluster (1) -
each
_ index (1) -
each
_ key (1) -
each
_ line (6) -
each
_ pair (2) -
each
_ slice (1) -
each
_ value (1) -
each
_ with _ index (1) -
each
_ with _ object (1) - eager (1)
- end (2)
-
enum
_ for (4) - eql? (2)
-
exclude
_ end? (1) - executable? (1)
-
executable
_ real? (1) - exited? (1)
- exitstatus (1)
- fdatasync (1)
- fdiv (2)
- feed (1)
-
fetch
_ values (2) - file? (1)
- filter (5)
- filter! (2)
-
filter
_ map (2) - find (1)
-
find
_ all (2) -
find
_ index (2) - finite? (1)
- first (2)
-
flat
_ map (3) - flatten (2)
- flatten! (1)
- flock (1)
- floor (2)
- force (1)
- ftype (1)
-
garbage
_ collect (1) - gid (1)
- grep (3)
-
grep
_ v (3) -
group
_ by (1) - grpowned? (1)
- gsub (4)
- gsub! (4)
- hash (4)
- index (3)
- infinite? (1)
- ino (1)
- inspect (7)
- isatty (1)
-
keep
_ if (2) - key (1)
- label (1)
- last (2)
- lazy (2)
- length (1)
- lineno (1)
- lines (6)
- lstat (1)
- magnitude (2)
- map (3)
- map! (1)
-
marshal
_ dump (1) - match (5)
- match? (3)
-
max
_ by (2) -
min
_ by (2) -
minmax
_ by (1) - mode (1)
- modulo (1)
- mtime (1)
-
named
_ captures (1) - names (1)
- nan? (1)
- negative? (3)
- next (1)
-
next
_ float (1) -
next
_ values (1) - nlink (1)
- none? (2)
- numerator (5)
- offset (2)
- one? (2)
- owned? (1)
- pack (2)
- partition (1)
- path (7)
- peek (1)
-
peek
_ values (1) - permutation (2)
- phase (3)
- pid (1)
- pipe? (1)
- positive? (2)
-
post
_ match (1) -
pre
_ match (1) -
prepend
_ features (1) -
prev
_ float (1) -
primitive
_ convert (4) - printf (2)
- private (1)
-
private
_ call? (1) -
private
_ class _ method (1) -
private
_ constant (1) -
private
_ instance _ methods (1) -
private
_ method _ defined? (1) -
private
_ methods (1) - quo (2)
- rand (3)
- rationalize (9)
- rdev (1)
-
rdev
_ major (1) -
rdev
_ minor (1) - readable? (1)
-
readable
_ real? (1) - regexp (1)
- reject (4)
- reject! (2)
-
remove
_ const (1) - reopen (2)
-
repeated
_ combination (2) -
repeated
_ permutation (2) - replicate (1)
-
report
_ on _ exception= (1) -
respond
_ to _ missing? (1) - result (1)
-
reverse
_ each (2) - rewind (2)
- rindex (2)
- rotate (1)
- rotate! (1)
- round (3)
-
ruby2
_ keywords (2) - saturday? (1)
- scan (2)
- select (5)
- select! (2)
- setgid? (1)
- setuid? (1)
- signaled? (1)
- size (6)
- size? (1)
-
slice
_ after (4) -
slice
_ before (5) -
slice
_ when (2) - socket? (1)
-
sort
_ by (1) -
sort
_ by! (1) -
source
_ location (4) - stat (1)
- state (1)
- status (2)
- step (11)
- sticky? (1)
- stime (1)
- stopped? (1)
- stopsig (1)
- strftime (1)
- string (1)
- sub (3)
- sub! (3)
- subsec (1)
- success? (1)
- symlink? (1)
- sync= (1)
- take (1)
-
take
_ while (4) - terminate (1)
- termsig (1)
- then (1)
- times (1)
-
to
_ a (1) -
to
_ binary (1) -
to
_ enum (4) -
to
_ f (7) -
to
_ i (3) -
to
_ path (2) -
to
_ proc (1) -
to
_ r (7) -
to
_ regexp (1) -
to
_ s (5) - tr (1)
- tr! (1)
-
tr
_ s (1) -
tr
_ s! (1) -
transform
_ keys (1) -
transform
_ keys! (1) -
transform
_ values (1) -
transform
_ values! (1) - truncate (5)
- tty? (1)
- uid (1)
- uniq (2)
- unpack (1)
- unpack1 (1)
- update (2)
- upto (1)
- utime (1)
-
values
_ at (4) -
with
_ index (4) -
with
_ object (2) -
world
_ readable? (1) -
world
_ writable? (1) - writable? (1)
-
writable
_ real? (1) - yield (1)
-
yield
_ self (1) - zero? (2)
- zip (2)
検索結果
先頭5件
-
Module
# private _ method _ defined?(name , inherit=true) -> bool (18310.0) -
インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が private であるときに true を返します。 そうでなければ false を返します。
インスタンスメソッド name がモジュールに定義されており、
しかもその可視性が private であるときに true を返します。
そうでなければ false を返します。
@param name Symbol か String を指定します。
@param inherit 真を指定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。
@see Module#method_defined?, Module#public_method_defined?, Module#protected_method_defined?
//e... -
NoMethodError
# private _ call? -> bool (18310.0) -
メソッド呼び出しが private なメソッドを呼び出せる形式 (関数形式(レシーバを省略した形式)) で呼ばれたかどうかを返します。
メソッド呼び出しが private なメソッドを呼び出せる形式
(関数形式(レシーバを省略した形式)) で呼ばれたかどうかを返します。 -
Numeric
# denominator -> Integer (18310.0) -
自身を Rational に変換した時の分母を返します。
自身を Rational に変換した時の分母を返します。
@return 分母を返します。
@see Numeric#numerator、Integer#denominator、Float#denominator、Rational#denominator、Complex#denominator -
Numeric
# negative? -> bool (18310.0) -
self が 0 未満の場合に true を返します。そうでない場合に false を返します。
self が 0 未満の場合に true を返します。そうでない場合に false を返します。
//emlist[例][ruby]{
-1.negative? # => true
0.negative? # => false
1.negative? # => false
//}
@see Numeric#positive? -
Numeric
# numerator -> Integer (18310.0) -
自身を Rational に変換した時の分子を返します。
自身を Rational に変換した時の分子を返します。
@return 分子を返します。
@see Numeric#denominator、Integer#numerator、Float#numerator、Rational#numerator、Complex#numerator -
Numeric
# truncate -> Integer (18310.0) -
0 から 自身までの整数で、自身にもっとも近い整数を返します。
0 から 自身までの整数で、自身にもっとも近い整数を返します。
//emlist[例][ruby]{
1.truncate #=> 1
1.2.truncate #=> 1
(-1.2).truncate #=> -1
(-1.5).truncate #=> -1
//}
@see Numeric#ceil, Numeric#floor, Numeric#round -
Object
# private _ methods(include _ inherited = true) -> [Symbol] (18310.0) -
そのオブジェクトが理解できる private メソッド名の一覧を返します。
そのオブジェクトが理解できる private メソッド名の一覧を返します。
@param include_inherited 偽となる値を指定すると自身のクラスのスーパークラスで定義されたメソッドを除きます。
@see Module#private_instance_methods,Object#methods,Object#singleton_methods -
Proc
# source _ location -> [String , Integer] | nil (18310.0) -
ソースコードのファイル名と行番号を配列で返します。
ソースコードのファイル名と行番号を配列で返します。
その手続オブジェクトが ruby で定義されていない(つまりネイティブ
である)場合は nil を返します。
//emlist[例][ruby]{
# /path/to/target.rb を実行
proc {}.source_location # => ["/path/to/target.rb", 1]
proc {}.source_location # => ["/path/to/target.rb", 2]
(eval "proc {}").source_location # => ... -
Random
# state -> Integer (18310.0) -
C言語レベルで定義されている構造体MTの状態を参照します。詳しくはrandom.c を参照してください。
C言語レベルで定義されている構造体MTの状態を参照します。詳しくはrandom.c を参照してください。 -
Regexp
# match?(str , pos = 0) -> bool (18310.0) -
指定された文字列 str に対して 位置 pos から自身が表す正規表現によるマッチングを行います。 マッチした場合 true を返し、マッチしない場合には false を返します。 また、$~ などパターンマッチに関する組み込み変数の値は変更されません。
指定された文字列 str に対して 位置 pos から自身が表す正規表現によるマッチングを行います。
マッチした場合 true を返し、マッチしない場合には false を返します。
また、$~ などパターンマッチに関する組み込み変数の値は変更されません。
//emlist[例][ruby]{
/R.../.match?("Ruby") # => true
/R.../.match?("Ruby", 1) # => false
/P.../.match?("Ruby") # => false
$& # => nil
//}
@see... -
RubyVM
:: InstructionSequence # absolute _ path -> String | nil (18310.0) -
self が表す命令シーケンスの絶対パスを返します。
self が表す命令シーケンスの絶対パスを返します。
self を文字列から作成していた場合は nil を返します。
例1:irb で実行した場合
iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
iseq.absolute_path
# => nil
例2: RubyVM::InstructionSequence.compile_file を使用した場合
# /tmp/method.... -
RubyVM
:: InstructionSequence # path -> String (18310.0) -
self が表す命令シーケンスの相対パスを返します。
self が表す命令シーケンスの相対パスを返します。
self の作成時に指定した文字列を返します。self を文字列から作成していた
場合は "<compiled>" を返します。
例1:irb で実行した場合
iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
iseq.path
# => "<compiled>"
例2: RubyVM::InstructionSequence.compi... -
String
# match(regexp , pos = 0) {|m| . . . } -> object (18310.0) -
regexp.match(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match を参照してください。
regexp.match(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match を参照してください。
//emlist[例: regexp のみの場合][ruby]{
'hello'.match('(.)\1') # => #<MatchData "ll" 1:"l">
'hello'.match('(.)\1')[0] # => "ll"
'hello'.match(/(.)\1/)[0] # => "ll"
'hello'.match('xx') # => nil
//}
... -
String
# match?(regexp , pos = 0) -> bool (18310.0) -
regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。
regexp.match?(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。
//emlist[例][ruby]{
"Ruby".match?(/R.../) #=> true
"Ruby".match?(/R.../, 1) #=> false
"Ruby".match?(/P.../) #=> false
$& #=> nil
//}
@see Regexp#match?, Symbol#match? -
Symbol
# match?(regexp , pos = 0) -> bool (18310.0) -
regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。
regexp.match?(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。
例:
:Ruby.match?(/R.../) # => true
:Ruby.match?('Ruby') # => true
:Ruby.match?('Ruby',1) # => false
:Ruby.match?('uby',1) # => true
:Ruby.match?(/P.../) # => false
$& ... -
SystemExit
# status -> Integer (18310.0) -
例外オブジェクトに保存された終了ステータスを返します。
例外オブジェクトに保存された終了ステータスを返します。
終了ステータスは Kernel.#exit や SystemExit.new などで設定されます。
例:
begin
exit 1
rescue SystemExit => err
p err.status # => 1
end
begin
raise SystemExit.new(1, "dummy exit")
rescue SystemExit => err
p err.status # => 1
end -
Thread
# status -> String | false | nil (18310.0) -
生きているスレッドの状態を文字列 "run"、"sleep", "aborting" のいず れかで返します。正常終了したスレッドに対して false、例外によ り終了したスレッドに対して nil を返します。
生きているスレッドの状態を文字列 "run"、"sleep", "aborting" のいず
れかで返します。正常終了したスレッドに対して false、例外によ
り終了したスレッドに対して nil を返します。
Thread#alive? が真を返すなら、このメソッドも真です。
例:
a = Thread.new { raise("die now") }
b = Thread.new { Thread.stop }
c = Thread.new { Thread.exit }
d = Thread.new { sleep }
d.kill ... -
Time
# saturday? -> bool (18310.0) -
self の表す時刻が土曜日である場合に true を返します。 そうでない場合に false を返します。
self の表す時刻が土曜日である場合に true を返します。
そうでない場合に false を返します。
//emlist[][ruby]{
t = Time.local(2006, 6, 10) # => 2006-06-10 00:00:00 +0900
p t.saturday? # => true
//} -
TracePoint
# path -> String (18310.0) -
イベントが発生したファイルのパスを返します。
イベントが発生したファイルのパスを返します。
@raise RuntimeError イベントフックの外側で実行した場合に発生します。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:call) do |tp|
p tp.path # => "/path/to/test.rb"
end
trace.enable
foo 1
//} -
UnboundMethod
# source _ location -> [String , Integer] | nil (18310.0) -
ソースコードのファイル名と行番号を配列で返します。
ソースコードのファイル名と行番号を配列で返します。
その手続オブジェクトが ruby で定義されていない(つまりネイティブ
である)場合は nil を返します。
//emlist[例][ruby]{
require 'time'
Time.instance_method(:zone).source_location # => nil
Time.instance_method(:httpdate).source_location # => ["/Users/user/.rbenv/versions/2.4.3/lib/ruby/2.4.0/time.rb", 654]
/... -
MatchData
# ==(other) -> bool (18010.0) -
self と other のマッチ対象になった文字列、元になった正規表現オブジェク ト、マッチした位置が等しければ true を返します。そうでない場合には false を返します。
self と other のマッチ対象になった文字列、元になった正規表現オブジェク
ト、マッチした位置が等しければ true を返します。そうでない場合には
false を返します。
@param other 比較対象のオブジェクトを指定します。
//emlist[文字列][ruby]{
s = "abc"
m1 = s.match("a")
m2 = s.match("b")
m1 == m2 # => false
m2 = s.match("a")
m1 == m2 # => true
//}
//emlist[正規表現][ruby]{
r = /abc/
m1 = r.mat... -
MatchData
# [](n) -> String | nil (18010.0) -
n 番目の部分文字列を返します。
n 番目の部分文字列を返します。
0 はマッチ全体を意味します。
n の値が負の時には末尾からのインデックスと見倣します(末尾の
要素が -1 番目)。n 番目の要素が存在しない時には nil を返します。
@param n 返す部分文字列のインデックスを指定します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~[0] # => "foobar"
p $~[1] # => "foo"
... -
MatchData
# [](name) -> String | nil (18010.0) -
name という名前付きグループにマッチした文字列を返します。
name という名前付きグループにマッチした文字列を返します。
@param name 名前(シンボルか文字列)
@raise IndexError 指定した名前が正規表現内に含まれていない場合に発生します
//emlist[例][ruby]{
/\$(?<dollars>\d+)\.(?<cents>\d+)/.match("$3.67")[:cents] # => "67"
/(?<alpha>[a-zA-Z]+)|(?<num>\d+)/.match("aZq")[:num] # => nil
//} -
MatchData
# [](range) -> [String] (18010.0) -
Range オブジェクト range の範囲にある要素からなる部分配列を返します。
Range オブジェクト range の範囲にある要素からなる部分配列を返します。
@param range start..end 範囲式。
//emlist[例][ruby]{
/(foo)(bar)/ =~ "foobarbaz"
p $~[0..2] # => ["foobar", "foo", "bar"]
//} -
MatchData
# [](start , length) -> [String] (18010.0) -
start 番目から length 個の要素を含む部分配列を返します。
start 番目から length 個の要素を含む部分配列を返します。
//emlist[例][ruby]{
/(foo)(bar)/ =~ "foobarbaz"
p $~[0, 3] # => ["foobar", "foo", "bar"]
//}
@see Array#[] -
MatchData
# begin(n) -> Integer | nil (18010.0) -
n 番目の部分文字列先頭のオフセットを返します。
n 番目の部分文字列先頭のオフセットを返します。
0 はマッチ全体を意味します。
n 番目の部分文字列がマッチしていなければ nilを返します。
@param n 部分文字列を指定する数値。
@raise IndexError 範囲外の n を指定した場合に発生します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.begin(0) # => 0
p $~.begin(1) # => 0
p $~.begin(2) # => 3
p $~.begin(3) # => nil
p $~.begin(4... -
MatchData
# captures -> [String] (18010.0) -
$1, $2, ... を格納した配列を返します。
$1, $2, ... を格納した配列を返します。
MatchData#to_a と異なり $& を要素に含みません。
グループにマッチした部分文字列がなければ対応する要素は nil になります。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~.captures # => ["foo", "bar", nil]
//}
@see MatchData#to_a, MatchData#named_captures -
MatchData
# end(n) -> Integer | nil (18010.0) -
n 番目の部分文字列終端のオフセットを返します。
n 番目の部分文字列終端のオフセットを返します。
0 はマッチ全体を意味します。
n 番目の部分文字列がマッチしていなければ nil を返します。
@param n 部分文字列を指定する数値。
@raise IndexError 範囲外の n を指定した場合に発生します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.end(0) # => 6
p $~.end(1) # => 3
p $~.end(2) # => 6
p $~.end(3) # => nil
p $~.end(4) # => ... -
MatchData
# eql?(other) -> bool (18010.0) -
self と other のマッチ対象になった文字列、元になった正規表現オブジェク ト、マッチした位置が等しければ true を返します。そうでない場合には false を返します。
self と other のマッチ対象になった文字列、元になった正規表現オブジェク
ト、マッチした位置が等しければ true を返します。そうでない場合には
false を返します。
@param other 比較対象のオブジェクトを指定します。
//emlist[文字列][ruby]{
s = "abc"
m1 = s.match("a")
m2 = s.match("b")
m1 == m2 # => false
m2 = s.match("a")
m1 == m2 # => true
//}
//emlist[正規表現][ruby]{
r = /abc/
m1 = r.mat... -
MatchData
# hash -> Integer (18010.0) -
self のマッチ対象になった文字列、元になった正規表現オブジェクト、マッチ した位置を元にハッシュ値を計算して返します。
self のマッチ対象になった文字列、元になった正規表現オブジェクト、マッチ
した位置を元にハッシュ値を計算して返します。 -
MatchData
# inspect -> String (18010.0) -
self の内容を人間に読みやすい文字列にして返します。
self の内容を人間に読みやすい文字列にして返します。
//emlist[例][ruby]{
puts /.$/.match("foo").inspect
# => #<MatchData "o">
puts /(.)(.)(.)/.match("foo").inspect
# => #<MatchData "foo" 1:"f" 2:"o" 3:"o">
puts /(.)(.)?(.)/.match("fo").inspect
# => #<MatchData "fo" 1:"f" 2:nil 3:"o">
puts /(?<foo>.)(?<bar>.)(?<baz>.)/.... -
MatchData
# length -> Integer (18010.0) -
部分文字列の数を返します(self.to_a.size と同じです)。
部分文字列の数を返します(self.to_a.size と同じです)。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.size # => 4
//} -
MatchData
# named _ captures -> Hash (18010.0) -
名前付きキャプチャをHashで返します。
名前付きキャプチャをHashで返します。
Hashのキーは名前付きキャプチャの名前です。Hashの値はキーの名前に対応した名前付きグループのうち最後にマッチした文字列です。
//emlist[例][ruby]{
m = /(?<a>.)(?<b>.)/.match("01")
m.named_captures # => {"a" => "0", "b" => "1"}
m = /(?<a>.)(?<b>.)?/.match("0")
m.named_captures # => {"a" => "0", "b" => nil}
m = /(?<a>.)(?<a>.)/.match("0... -
MatchData
# names -> [String] (18010.0) -
名前付きキャプチャの名前を文字列配列で返します。
名前付きキャプチャの名前を文字列配列で返します。
self.regexp.names と同じです。
//emlist[例][ruby]{
/(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").names
# => ["foo", "bar", "baz"]
m = /(?<x>.)(?<y>.)?/.match("a") # => #<MatchData "a" x:"a" y:nil>
m.names # => ["x", "y"]
//} -
MatchData
# offset(n) -> [Integer , Integer] | [nil , nil] (18010.0) -
n 番目の部分文字列のオフセットの配列 [start, end] を返 します。
n 番目の部分文字列のオフセットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(n), self.end(n) ]
//}
と同じです。n番目の部分文字列がマッチしていなければ
[nil, nil] を返します。
@param n 部分文字列を指定する数値
@raise IndexError 範囲外の n を指定した場合に発生します。
@see MatchData#begin, MatchData#end -
MatchData
# offset(name) -> [Integer , Integer] | [nil , nil] (18010.0) -
name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。
name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}
と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil] を返します。
@param name 名前(シンボルか文字列)
@raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。
//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\... -
MatchData
# regexp -> Regexp (18010.0) -
自身の元になった正規表現オブジェクトを返します。
自身の元になった正規表現オブジェクトを返します。
//emlist[例][ruby]{
m = /a.*b/.match("abc")
m.regexp # => /a.*b/
//} -
MatchData
# size -> Integer (18010.0) -
部分文字列の数を返します(self.to_a.size と同じです)。
部分文字列の数を返します(self.to_a.size と同じです)。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.size # => 4
//} -
MatchData
# string -> String (18010.0) -
マッチ対象になった文字列の複製を返します。
マッチ対象になった文字列の複製を返します。
返す文字列はフリーズ(Object#freeze)されています。
//emlist[例][ruby]{
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.string # => "THX1138."
//} -
MatchData
# to _ a -> [String] (18010.0) -
$&, $1, $2,... を格納した配列を返します。
$&, $1, $2,... を格納した配列を返します。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
//}
@see MatchData#captures -
MatchData
# to _ s -> String (18010.0) -
マッチした文字列全体を返します。
マッチした文字列全体を返します。
//emlist[例][ruby]{
/bar/ =~ "foobarbaz"
p $~ # => #<MatchData:0x401b1be4>
p $~.to_s # => "bar"
//} -
Enumerator
:: Lazy # chunk(initial _ state) {|elt , state| . . . } -> Enumerator :: Lazy (9910.0) -
Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.chunk{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007f8bf18118f0>:each>>
1.step.lazy.chunk{ |n| n % 3 == 0 }.take(5).force
# => [[false, [1, 2]], [true, [3]], [false, [4, 5... -
Enumerator
:: Lazy # slice _ before(initial _ state) {|elt , state| bool } -> Enumerator :: Lazy (9910.0) -
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>
1.step.lazy.slice_before { |e| e % 3 == 0 }.take(5).force
# => [[1, 2], [3, 4, 5], [6... -
Enumerator
:: Lazy # grep(pattern) {|item| . . . } -> Enumerator :: Lazy (9610.0) -
Enumerable#grep と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#grep と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep(/\A(\d)\1+\z/)>
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/).... -
Enumerator
:: Lazy # grep _ v(pattern) {|item| . . . } -> Enumerator :: Lazy (9610.0) -
Enumerable#grep_v と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#grep_v と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep_v(/(\d).*\1/)>
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/).t... -
Enumerator
:: Lazy # slice _ after(pattern) -> Enumerator :: Lazy (9610.0) -
Enumerable#slice_after と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#slice_after と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_after { |e| e % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007fd73980e6f8>:each>>
1.step.lazy.slice_after { |e| e % 3 == 0 }.take(5).force
# => [[1, 2, 3], [4, 5, 6], [... -
Enumerator
:: Lazy # slice _ before(pattern) -> Enumerator :: Lazy (9610.0) -
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>
1.step.lazy.slice_before { |e| e % 3 == 0 }.take(5).force
# => [[1, 2], [3, 4, 5], [6... -
Rational
# *(other) -> Rational | Float (9610.0) -
積を計算します。
積を計算します。
@param other 自身に掛ける数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r * 2 # => (3/2)
r * 4 # => (3/1)
r * 0.5 # => 0.375
r * Rational(1, 2) # => (3/8)
//} -
Rational
# **(other) -> Rational | Float (9610.0) -
冪(べき)乗を計算します。
冪(べき)乗を計算します。
@param other 自身を other 乗する数
other に Float を指定した場合は、計算結果を Float で返しま
す。other が有理数であっても、計算結果が無理数だった場合は Float
を返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r ** Rational(2, 1) # => (9/16)
r ** 2 # => (9/16)
r ** 2.0 # => 0.5625
r ** Rational(1, 2) # => 0.866... -
Rational
# +(other) -> Rational | Float (9610.0) -
和を計算します。
和を計算します。
@param other 自身に足す数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r + Rational(1, 2) # => (5/4)
r + 1 # => (7/4)
r + 0.5 # => 1.25
//} -
Rational
# -(other) -> Rational | Float (9610.0) -
差を計算します。
差を計算します。
@param other 自身から引く数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r - 1 # => (-1/4)
r - 0.5 # => 0.25
//} -
Rational
# / (other) -> Rational | Float (9610.0) -
商を計算します。
商を計算します。
@param other 自身を割る数
other に Float を指定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroD... -
Rational
# quo(other) -> Rational | Float (9610.0) -
商を計算します。
商を計算します。
@param other 自身を割る数
other に Float を指定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroD... -
ARGF
. class # path -> String (9310.0) -
現在開いている処理対象のファイル名を返します。
現在開いている処理対象のファイル名を返します。
標準入力に対しては - を返します。
組み込み変数 $FILENAME と同じです。
$ echo "foo" > foo
$ echo "bar" > bar
$ echo "glark" > glark
$ ruby argf.rb foo bar glark
ARGF.filename # => "foo"
ARGF.read(5) # => "foo\nb"
ARGF.filename # => "bar"
ARGF.skip
ARGF.filename # => "glark" -
Complex
# conjugate -> Complex (9310.0) -
自身の共役複素数を返します。
自身の共役複素数を返します。
//emlist[例][ruby]{
Complex(1, 2).conj # => (1-2i)
//} -
Complex
# to _ r -> Rational (9310.0) -
自身を Rational に変換します。
自身を Rational に変換します。
@param eps 許容する誤差。常に無視されます。
@raise RangeError 虚部が実数か、0 ではない場合に発生します。
//emlist[例][ruby]{
Complex(3).to_r # => (3/1)
Complex(3, 2).to_r # => RangeError
//} -
Enumerator
# +(enum) -> Enumerator :: Chain (9310.0) -
自身と enum 引数を続けて繰り返す Enumerator::Chain を返します。
自身と enum 引数を続けて繰り返す Enumerator::Chain を返します。
//emlist[例][ruby]{
e = (1..3).each + [4, 5]
e.to_a #=> [1, 2, 3, 4, 5]
//}
@see Enumerable#chain -
Enumerator
# each(*args) -> Enumerator (9310.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
生成時のパラメータに従ってブロックを繰り返します。
*args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。
ブロック付きで呼び出された場合は、
生成時に指定したイテレータの戻り値をそのまま返します。
@param args 末尾へ追加する引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } ... -
Enumerator
# size -> Integer | Float :: INFINITY | nil (9310.0) -
self の要素数を返します。
self の要素数を返します。
要素数が無限の場合は Float::INFINITY を返します。
Enumerator.new に Proc オブジェクトを指定していた場合はその
実行結果を返します。呼び出した時に要素数が不明であった場合は nil を返し
ます。
//emlist[例][ruby]{
(1..100).to_a.permutation(4).size # => 94109400
loop.size # => Float::INFINITY
(1..100).drop_while.size # => nil
//}
@see Enumerator.new -
Enumerator
# with _ index(offset = 0) -> Enumerator (9310.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。
インデックスは offset から始まります。
ブロックを指定した場合の戻り値は生成時に指定したレシーバ自身です。
//emlist[例][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 "stringi... -
Enumerator
# with _ object(obj) -> Enumerator (9310.0) -
繰り返しの各要素に obj を添えてブロックを繰り返し、obj を返り値として返します。
繰り返しの各要素に obj を添えてブロックを繰り返し、obj を返り値として返します。
obj には任意のオブジェクトを渡すことができます。
ブロックが渡されなかった場合は、上で説明した繰り返しを実行し、
最後に obj を返す Enumerator を返します。
//emlist[例][ruby]{
# 0,1,2 と呼びだす enumeratorを作る
to_three = Enumerator.new do |y|
3.times do |x|
y << x
end
end
to_three_with_string = to_three.with_object... -
Enumerator
:: Chain # each(*args) -> Enumerator (9310.0) -
まず最初の繰り返し可能なオブジェクトの each メソッドを args 引数とともに呼び出した後、続く繰り返し可能なオブジェクト も同様に呼び出します。
まず最初の繰り返し可能なオブジェクトの each メソッドを
args 引数とともに呼び出した後、続く繰り返し可能なオブジェクト
も同様に呼び出します。
ブロックが渡されない場合は Enumerator を返します。 -
Enumerator
:: Chain # size -> Integer | Float :: INFINITY | nil (9310.0) -
合計の要素数を返します。
合計の要素数を返します。
それぞれの列挙可能なオブジェクトのサイズの合計値を返します。
ただし、列挙可能なオブジェクトが1つでも nil か Float::INFINITY
を返した場合、それを合計の要素数として返します。 -
Enumerator
:: Lazy # chunk {|elt| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#chunk と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.chunk{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007f8bf18118f0>:each>>
1.step.lazy.chunk{ |n| n % 3 == 0 }.take(5).force
# => [[false, [1, 2]], [true, [3]], [false, [4, 5... -
Enumerator
:: Lazy # chunk _ while {|elt _ before , elt _ after| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#chunk_while と同じですが、Enumerator ではなく Enumerator::Lazy を返します。
Enumerable#chunk_while と同じですが、Enumerator ではなく Enumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。 -
Enumerator
:: Lazy # collect {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#map と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#map と同じですが、配列ではなくEnumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.map{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:map>
1.step.lazy.collect{ |n| n.succ }.take(10).force
# => [2, 3, 4, 5, 6, 7, 8,... -
Enumerator
:: Lazy # drop(n) -> Enumerator :: Lazy (9310.0) -
Enumerable#drop と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#drop と同じですが、配列ではなくEnumerator::Lazy を返します。
@param n 要素数を指定します。
@raise ArgumentError n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
1.step.lazy.drop(3)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:drop(3)>
1.step.lazy.drop(3).take(10).force
# => [4, 5, 6, 7, 8, 9, 10, 1... -
Enumerator
:: Lazy # drop _ while {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#drop_while と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#drop_while と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.drop_while { |i| i < 42 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:drop_while>
1.step.lazy.drop_while { |i| i < 42 }.take(10).force
# => [42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
//... -
Enumerator
:: Lazy # eager -> Enumerator (9310.0) -
自身を遅延評価しない Enumerator に変換して返します。
自身を遅延評価しない Enumerator に変換して返します。
//emlist[例][ruby]{
lazy_enum = (1..).each.lazy
# select が遅延評価されるので終了する
p lazy_enum.class # => Enumerator::Lazy
p lazy_enum.select { |n| n.even? }.first(5)
# => [2, 4, 6, 8, 10]
# select が遅延評価されないので終了しない
enum = lazy_enum.eager
p enum.class # => Enumerator
p enum.s... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) -> Enumerator :: Lazy (9310.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
Object#to_enum と同じですが、Enumerator::Lazy を返します。
to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。
//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) ... -
Enumerator
:: Lazy # enum _ for(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (9310.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
Object#to_enum と同じですが、Enumerator::Lazy を返します。
to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。
//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) ... -
Enumerator
:: Lazy # filter {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#select と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#select と同じですが、配列ではなくEnumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:find_all>
1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6,... -
Enumerator
:: Lazy # filter _ map {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.filter_map { |n| n * 2 if n.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: (1.step)>:filter_map>
1.step.lazy.filter_map { |n| n * 2 if n.even? }.take(10).fo... -
Enumerator
:: Lazy # find _ all {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#select と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#select と同じですが、配列ではなくEnumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:find_all>
1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6,... -
Enumerator
:: Lazy # map {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#map と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#map と同じですが、配列ではなくEnumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.map{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:map>
1.step.lazy.collect{ |n| n.succ }.take(10).force
# => [2, 3, 4, 5, 6, 7, 8,... -
Enumerator
:: Lazy # reject {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#reject と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#reject と同じですが、配列ではなくEnumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.reject { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:reject>
1.step.lazy.reject { |i| i.even? }.take(10).force
# => [1, 3, 5, 7, ... -
Enumerator
:: Lazy # select {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#select と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#select と同じですが、配列ではなくEnumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.find_all { |i| i.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:find_all>
1.step.lazy.select { |i| i.even? }.take(10).force
# => [2, 4, 6,... -
Enumerator
:: Lazy # slice _ after {|elt| bool } -> Enumerator :: Lazy (9310.0) -
Enumerable#slice_after と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#slice_after と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_after { |e| e % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x007fd73980e6f8>:each>>
1.step.lazy.slice_after { |e| e % 3 == 0 }.take(5).force
# => [[1, 2, 3], [4, 5, 6], [... -
Enumerator
:: Lazy # slice _ before {|elt| bool } -> Enumerator :: Lazy (9310.0) -
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>
1.step.lazy.slice_before { |e| e % 3 == 0 }.take(5).force
# => [[1, 2], [3, 4, 5], [6... -
Enumerator
:: Lazy # slice _ when {|elt _ before , elt _ after| bool } -> Enumerator :: Lazy (9310.0) -
Enumerable#slice_when と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#slice_when と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_when { |i, j| (i + j) % 5 == 0 }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007fce84118348>:each>>
1.step.lazy.slice_when { |i, j| (i + j) % 5 == 0 }.take(5).force
# => [[1, 2]... -
Enumerator
:: Lazy # take(n) -> Enumerator :: Lazy (9310.0) -
Enumerable#take と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#take と同じですが、配列ではなくEnumerator::Lazy を返します。
n が大きな数 (100000とか) の場合に備えて再定義されています。
配列が必要な場合は Enumerable#first を使って下さい。
@param n 要素数を指定します。
@raise ArgumentError n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
1.step.lazy.take(5)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:... -
Enumerator
:: Lazy # take _ while -> Enumerator :: Lazy (9310.0) -
Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".."z":cycle>)>:take_while>
1.step.lazy.... -
Enumerator
:: Lazy # take _ while {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#take_while と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle).take_while { |e| e.first < 100_000 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".."z":cycle>)>:take_while>
1.step.lazy.... -
Enumerator
:: Lazy # to _ enum(method = :each , *args) -> Enumerator :: Lazy (9310.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
Object#to_enum と同じですが、Enumerator::Lazy を返します。
to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。
//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) ... -
Enumerator
:: Lazy # to _ enum(method = :each , *args) {|*args| block} -> Enumerator :: Lazy (9310.0) -
Object#to_enum と同じですが、Enumerator::Lazy を返します。
Object#to_enum と同じですが、Enumerator::Lazy を返します。
to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が正しく引き継がれるように、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。
//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) ... -
Enumerator
:: Lazy # uniq -> Enumerator :: Lazy (9310.0) -
Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。 -
Enumerator
:: Lazy # uniq {|item| . . . } -> Enumerator :: Lazy (9310.0) -
Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#uniq と同じですが、配列ではなく Enumerator::Lazy を返します。 -
Enumerator
:: Lazy # with _ index(offset = 0) -> Enumerator :: Lazy (9310.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。
インデックスは offset から始まります。
ブロックを指定した場合の戻り値は生成時に指定したレシーバ自身です。
//emlist[][ruby]{
("a"..).lazy.with_index(1) { |it, index| puts "#{index}:#{it}" }.take(3).force
# => 1:a
# 2:b
# 3:c
//}
@see Enumerator#with_index -
Enumerator
:: Lazy # with _ index(offset = 0) {|(*args) , idx| . . . } -> Enumerator :: Lazy (9310.0) -
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。
生成時のパラメータに従って、要素にインデックスを添えて繰り返します。
インデックスは offset から始まります。
ブロックを指定した場合の戻り値は生成時に指定したレシーバ自身です。
//emlist[][ruby]{
("a"..).lazy.with_index(1) { |it, index| puts "#{index}:#{it}" }.take(3).force
# => 1:a
# 2:b
# 3:c
//}
@see Enumerator#with_index -
Enumerator
:: Lazy # zip(*lists) -> Enumerator :: Lazy (9310.0) -
Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
ただし一貫性のため、ブロック付きで呼び出した場合は Enumerable#zip と
同じ挙動になります。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".."z":cycle>)>
1.step.lazy.zip(('a'..'z').cycle)... -
Float
# %(other) -> Float (9310.0) -
算術演算子。剰余を計算します。
算術演算子。剰余を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 剰余
3.0 % 1.2 # => 0.6000000000000001
3.0 % 0.0 # ZeroDivisionError
//} -
Float
# *(other) -> Float (9310.0) -
算術演算子。積を計算します。
算術演算子。積を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 積
2.4 * 3 # => 7.2
//} -
Float
# **(other) -> Float (9310.0) -
算術演算子。冪を計算します。
算術演算子。冪を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 冪
1.2 ** 3.0 # => 1.7279999999999998
3.0 + 4.5 - 1.3 / 2.4 * 3 % 1.2 ** 3.0 # => 5.875
0.0 ** 0 # => 1.0
//} -
Float
# +(other) -> Float (9310.0) -
算術演算子。和を計算します。
算術演算子。和を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 和
3.0 + 4.5 # => 7.5
//} -
Float
# -(other) -> Float (9310.0) -
算術演算子。差を計算します。
算術演算子。差を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 差
4.5 - 1.3 # => 3.2
//} -
Float
# -@ -> Float (9310.0) -
単項演算子の - です。 self の符号を反転させたものを返します。
単項演算子の - です。
self の符号を反転させたものを返します。
//emlist[例][ruby]{
- 1.2 # => -1.2
- -1.2 # => 1.2
//} -
Float
# / (other) -> Float (9310.0) -
算術演算子。商を計算します。
算術演算子。商を計算します。
@param other 二項演算の右側の引数(対象)
//emlist[例][ruby]{
# 商
1.3 / 2.4 # => 0.541666666666667
1.0 / 0 # => Infinity
//} -
Float
# abs -> Float (9310.0) -
自身の絶対値を返します。
自身の絶対値を返します。
//emlist[例][ruby]{
34.56.abs # => 34.56
-34.56.abs # => 34.56
//} -
Float
# angle -> 0 | Float (9310.0) -
自身の偏角(正の数なら 0、負の数なら Math::PI)を返します。
自身の偏角(正の数なら 0、負の数なら Math::PI)を返します。
//emlist[例][ruby]{
1.arg # => 0
-1.arg # => 3.141592653589793
//}
ただし、自身が NaN(Not a number) であった場合は、NaN を返します。 -
Float
# arg -> 0 | Float (9310.0) -
自身の偏角(正の数なら 0、負の数なら Math::PI)を返します。
自身の偏角(正の数なら 0、負の数なら Math::PI)を返します。
//emlist[例][ruby]{
1.arg # => 0
-1.arg # => 3.141592653589793
//}
ただし、自身が NaN(Not a number) であった場合は、NaN を返します。