るりまサーチ

最速Rubyリファレンスマニュアル検索!
134件ヒット [1-100件を表示] (0.045秒)

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

クラス

キーワード

検索結果

<< 1 2 > >>

String#scan(pattern) -> [String] | [[String]] (18145.0)

self に対して pattern を繰り返しマッチし、 マッチした部分文字列の配列を返します。

...[例][ruby]{
p "foobar".scan(/../) # => ["fo", "ob", "ar"]
p "foobar".scan("o") # => ["o", "o"]
p "foobarbazfoobarbaz".scan(/ba./) # => ["bar", "baz", "bar", "baz"]

p "foobar".scan(/(.)/) # => [["f"], ["o"], ["o"], ["b"], ["a"], ["r"]]

p "foobarbazfoobarbaz".scan(/(ba...

String#scan(pattern) {|s| ... } -> self (18135.0)

pattern がマッチした部分文字列をブロックに渡して実行します。 pattern が正規表現で括弧を含む場合は、 括弧で括られたパターンにマッチした文字列の配列を渡します。

...する部分文字列または正規表現

//emlist[例][ruby]{
"foobarbazfoobarbaz".scan(/ba./) {|s| p s }
# "bar"
# "baz"
# "bar"
# "baz"

"foobarbazfoobarbaz".scan("ba") {|s| p s }
# "ba"
# "ba"
# "ba"
# "ba"

"foobarbazfoobarbaz".scan(/(ba)(.)/) {|s| p s }
# ["ba", "r"]
# ["ba", "z"]
# ["ba", "...

Enumerator#each -> self (63.0)

生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。

...引数

//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"

enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"...
...# "Hacker"

str.scan(/\w+/) {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
//}

//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/)...
...# => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]

obj = Object.new

def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end

enum = obj.to_enu...

Enumerator#each {...} -> object (63.0)

生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。

...引数

//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"

enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"...
...# "Hacker"

str.scan(/\w+/) {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
//}

//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/)...
...# => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]

obj = Object.new

def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end

enum = obj.to_enu...

Enumerator#each(*args) -> Enumerator (63.0)

生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。

...引数

//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"

enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"...
...# "Hacker"

str.scan(/\w+/) {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
//}

//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/)...
...# => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]

obj = Object.new

def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end

enum = obj.to_enu...

絞り込み条件を変える

Enumerator#each(*args) {...} -> object (63.0)

生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。

...引数

//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"

enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"...
...# "Hacker"

str.scan(/\w+/) {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
//}

//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/)...
...# => ["Hello", "world"]
"Hello, world!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]

obj = Object.new

def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end

enum = obj.to_enu...

Method#<<(callable) -> Proc (33.0)

self と引数を合成した Proc を返します。

...ェクト。

//emlist[例][ruby]{
def f(x)
x * x
end

def g(x)
x + x
end

# (3 + 3) * (3 + 3)
p (method(:f) << method(:g)).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('t...
...estfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = method(:pp) << WordScanner << File.method(:read)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

Method#>>(callable) -> Proc (33.0)

self と引数を合成した Proc を返します。

...ェクト。

//emlist[例][ruby]{
def f(x)
x * x
end

def g(x)
x + x
end

# (3 * 3) + (3 * 3)
p (method(:f) >> method(:g)).call(3) # => 18
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('t...
...estfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = File.method(:read) >> WordScanner >> method(:pp)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

Proc#>>(callable) -> Proc (33.0)

self と引数を合成した Proc を返します。

...オブジェクト。

//emlist[例][ruby]{
f = proc { |x| x * x }
g = proc { |x| x + x }

# (3 * 3) + (3 * 3)
p (f >> g).call(3) # => 18
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfil...
...e', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = proc { |fname| File.read(fname) } >> WordScanner >> method(:p)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Method#<<, Method#>>...

String#gsub(pattern, replace) -> String (30.0)

文字列中で pattern にマッチする部分全てを 文字列 replace で置き換えた文字列を生成して返します。

...場合は全く同じ文字列にだけマッチする
@param replace pattern で指定した文字列と置き換える文字列

//emlist[例][ruby]{
p 'abcdefg'.gsub(/def/, '!!') # => "abc!!g"
p 'abcabc'.gsub(/b/, '<<\&>>') # => "a<<b>>ca<<b>>c"
p 'xxbbxbb'.gsub(/x+(b+)/, 'X<<...
...二重にエスケープしなければなりません。

//emlist[ひとつめの括弧の内容に置き換えるときによくある間違い][ruby]{
p 'xbbb-xbbb'.gsub(/x(b+)/, "#{$1}") # => "-" # NG
p 'xbbb-xbbb'.gsub(/x(b+)/, "\1") # => "1-1" # NG
p 'xbbb-xbbb'.gsub(/x(b+)...
...OK
p 'xbbb-xbbb'.gsub(/x(b+)/, '\\1') # => "bbb-bbb" # OK
//}

//emlist[バックスラッシュを倍にするときによくある間違い][ruby]{
puts '\n'.gsub(/\\/, "\\\\") # => \n # NG
puts '\n'.gsub(/\\/, '\\\\') # => \n # NG
puts '\n'.gsub(/\\/, "\\\\\\\\") # => \\n # O...

絞り込み条件を変える

Proc#<<(callable) -> Proc (27.0)

self と引数を合成した Proc を返します。

...オブジェクト。

//emlist[例][ruby]{
f = proc { |x| x * x }
g = proc { |x| x + x }

# (3 + 3) * (3 + 3)
p (f << g).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfil...
...e', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = proc { |data| puts "word count: #{data.size}" } << WordScanner << File.method(:read)
pipeline.call('testfile') # => word count: 4
//}

@see Method#<<, Method#>>...
<< 1 2 > >>