るりまサーチ

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

別のキーワード

  1. matrix l
  2. kernel $-l
  3. _builtin $-l
  4. lupdecomposition l
  5. l matrix

ライブラリ

クラス

キーワード

検索結果

StringScanner#<<(str) -> self (21213.0)

操作対象の文字列に対し str を破壊的に連結します。 マッチ記録は変更されません。

...す。
マッチ記録は変更されません。

selfを返します。

@param str 操作対象の文字列に対し str を破壊的に連結します。

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test') # => #<StringScanner 0/4 @ "test">
s.match(/\w(\w*)/) # => "...
...# => "est"
s << ' string' # => #<StringScanner 4/11 "test" @ " stri...">
s[0] # => "test"
s[1] # => "est"
s.match(/\s+/) # => " "
s.match(/\w+/) # => "string"
//}

この操作は StringScanner.new に...
...渡した文字列にも影響することがあります。

//emlist[例][ruby]{
require 'strscan'

str = 'test'
s = StringScanner.new(str) # => #<StringScanner 0/4 @ "test">
s << ' string' # => #<StringScanner 0/11 @ "test ...">
str # => "test string"
//}...

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

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

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

戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を callable に渡して呼び出し、
その戻り値を self に渡して呼び出した結果を返します...
...なります。

@param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。

//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('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

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

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

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

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

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

戻り値の Proc は可変長の引数を受け取ります。
戻り値の Proc を呼び出すと、まず受け取った引数を callable に渡して呼び出し、
その戻り値を self に渡して呼び出した結果を返します...
...allable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。

//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 WordScan...
...ner
def self.call(str)
str.scan(/\w+/)
end
end

File.write('testfile', <<~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#>>...

StringScanner#concat(str) -> self (6113.0)

操作対象の文字列に対し str を破壊的に連結します。 マッチ記録は変更されません。

...す。
マッチ記録は変更されません。

selfを返します。

@param str 操作対象の文字列に対し str を破壊的に連結します。

//emlist[例][ruby]{
require 'strscan'

s = StringScanner.new('test') # => #<StringScanner 0/4 @ "test">
s.match(/\w(\w*)/) # => "...
...# => "est"
s << ' string' # => #<StringScanner 4/11 "test" @ " stri...">
s[0] # => "test"
s[1] # => "est"
s.match(/\s+/) # => " "
s.match(/\w+/) # => "string"
//}

この操作は StringScanner.new に...
...渡した文字列にも影響することがあります。

//emlist[例][ruby]{
require 'strscan'

str = 'test'
s = StringScanner.new(str) # => #<StringScanner 0/4 @ "test">
s << ' string' # => #<StringScanner 0/11 @ "test ...">
str # => "test string"
//}...

Enumerator#each -> self (137.0)

生成時のパラメータに従ってブロックを繰り返します。 *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 } # => "Yet"
#...
...tr.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_enum :each_arg, :a, :x...

絞り込み条件を変える

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

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

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

置換文字列 replace 中の \& と \0 はマッチした部分文字列に、
\1 ... \9 は n 番目の括弧の内容に置き換えられます。
置換文字...
...チする
@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<<\1>>') # => "X<<bb>>X<<bb>>"
p '2.5'.gsub('....
...', ',') # => "2,5"
//}

注意:

第 2 引数 replace に $1 を埋め込んでも意図した結果にはなりません。
この文字列が評価される時点ではまだ正規表現マッチが行われておらず、
$1 がセットされていないからです。

また、gsub では「\...