るりまサーチ

最速Rubyリファレンスマニュアル検索!
1008件ヒット [1-100件を表示] (0.110秒)
トップページ > クエリ:t[x] > クエリ:Ruby[x] > クエリ:$[x] > 種類:インスタンスメソッド[x]

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. matrix t
  4. t61string new
  5. fiddle type_size_t

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

String#split(sep = $;, limit = 0) -> [String] (6291.0)

第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。 ブロックを指定すると、配列を返す代わりに分割した文字列で ブロックを呼び出します。

...第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、
結果を文字列の配列で返します。

第 1 引数 sep は以下のいずれかです。

: 正規表現
正規表現にマッチする部分で分割する。
特に、括弧に...
...バイトの空白文字 ' '
先頭の連続する空白を除いたうえで、連続する空白で分割する。
: nil
常に $; で分割する。 $; も nil の場合は、1 バイトの空白文字を指定したのと同じ動作となる。
: 空文字列 '' あるいは空文字...
...が配列に含まれます。

第 2 引数 limit は以下のいずれかです。

: limit > 0
最大 limit 個の文字列に分割する
: limit == 0
分割個数制限はなしで、配列末尾の空文字列を取り除く
: limit < 0
分割個数の制限はなし

@param sep...
...第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、
結果を文字列の配列で返します。
ブロックを指定すると、配列を返す代わりに分割した文字列で
ブロックを呼び出します。

第 1 引数 sep は以下...

String#split(sep = $;, limit = 0) {|s| ... } -> self (6291.0)

第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。 ブロックを指定すると、配列を返す代わりに分割した文字列で ブロックを呼び出します。

...第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、
結果を文字列の配列で返します。
ブロックを指定すると、配列を返す代わりに分割した文字列で
ブロックを呼び出します。

第 1 引数 sep は以下...
...バイトの空白文字 ' '
先頭の連続する空白を除いたうえで、連続する空白で分割する。
: nil
常に $; で分割する。 $; も nil の場合は、1 バイトの空白文字を指定したのと同じ動作となる。
: 空文字列 '' あるいは空文字...
...が配列に含まれます。

第 2 引数 limit は以下のいずれかです。

: limit > 0
最大 limit 個の文字列に分割する
: limit == 0
分割個数制限はなしで、配列末尾の空文字列を取り除く
: limit < 0
分割個数の制限はなし

@param sep...

ARGF.class#gets(rs = $/) -> String | nil (6273.0)

ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。

...imit 最大の読み込みバイト数


例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets # => "line1\n"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets(...
...# => "li"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("e") # => "line"


例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("") #...
...=> "line1\nline2\nline3\n\n"

@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc...

ARGF.class#gets(rs = $/, chomp: false) -> String | nil (6273.0)

ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。

...ド)。

@param limit 最大の読み込みバイト数

@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets...
...# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets(2) # => "li"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("e") # => "line"


例:
# $ e...
...cho "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("") # => "line1\nline2\nline3\n\n"

@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc...

ARGF.class#readbyte -> Integer (6219.0)

自身から 1 バイトを読み込み整数として返します。 既に EOF に達していれば EOFError が発生します。

...が発生します。

@raise EOFError 既に EOF に達している場合に発生します。

$
echo "foo" > file
$
ruby argf.rb file

ARGF.readbyte # => 102
ARGF.readbyte # => 111
ARGF.readbyte # => 111
ARGF.readbyte # => 10
ARGF.readbyte # => end of file reached (EOFError)...

絞り込み条件を変える

StringIO#gets(rs = $/) -> String | nil (6207.0)

自身から 1 行読み込んで、その文字列を返します。文字列の終端に到達した時には nil を返します。 $_ に読み込んだ行がセットされます。

...自身から 1 行読み込んで、その文字列を返します。文字列の終端に到達した時には nil を返します。
$
_ に読み込んだ行がセットされます。

@param rs 行の区切りを文字列で指定します。rs に nil を指定すると行区切りなしとみ...
...ror 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge")
a.gets #=> "hoge"
$
_ #=> "hoge"
a.gets #=> nil
$
_ #=> nil
//}

@see $/...

ARGF.class#gets(limit) -> String | nil (6173.0)

ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。

...imit 最大の読み込みバイト数


例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets # => "line1\n"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets(...
...# => "li"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("e") # => "line"


例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("") #...
...=> "line1\nline2\nline3\n\n"

@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc...

ARGF.class#gets(limit, chomp: false) -> String | nil (6173.0)

ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。

...ド)。

@param limit 最大の読み込みバイト数

@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets...
...# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets(2) # => "li"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("e") # => "line"


例:
# $ e...
...cho "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("") # => "line1\nline2\nline3\n\n"

@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc...

ARGF.class#gets(rs, limit) -> String | nil (6173.0)

ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。

...imit 最大の読み込みバイト数


例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets # => "line1\n"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets(...
...# => "li"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("e") # => "line"


例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("") #...
...=> "line1\nline2\nline3\n\n"

@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc...

ARGF.class#gets(rs, limit, chomp: false) -> String | nil (6173.0)

ARGFの現在位置から一行ずつ文字列として読み込みます。EOF に到達した時に は nil を返します。

...ド)。

@param limit 最大の読み込みバイト数

@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets...
...# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets(2) # => "li"

例:
# $ echo "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("e") # => "line"


例:
# $ e...
...cho "line1\nline2\nline3\n\nline4\n" > test.txt
# $ ruby test.rb test.txt

# test.rb
ARGF.gets("") # => "line1\nline2\nline3\n\n"

@see Kernel.#gets, IO#gets, ARGF.class#getbyte, ARGF.class#getc...

絞り込み条件を変える

Enumerable#sort_by -> Enumerator (6161.0)

ブロックの評価結果を <=> メソッドで比較することで、self を昇 順にソートします。ソートされた配列を新たに生成して返します。

...emlist[例][ruby]{
class Array
def sort_by
self.map {|i| [yield(i), i] }.
sort {|a, b| a[0] <=> b[0] }.
map {|i| i[1]}
end
end
//}

Enumerable#sort と比較して sort_by が優れている点として、
比較条件が複雑な場合の速度が挙げられます。
sort_by...
...ます。
従って downcase の実行速度が遅ければ sort の速度が致命的に低下します。

//emlist[][ruby]{
p ["BAR", "FOO", "bar", "foo"].sort {|a, b| a.downcase <=> b.downcase }
//}

一方、次のように sort_by を使うと downcase の実行回数は要素数と同じで...
...//emlist[][ruby]{
p ["BAR", "FOO", "bar", "foo"].sort_by {|v| v.downcase }
//}

以下の、実行回数の検証結果を参照してみてください。

//emlist[][ruby]{
class Integer
def count
$
n += 1
self
end
end

ary = []
1.upto(1000) {|v| ary << rand(v) }

$
n = 0
ary.sort {|a,b|...

Enumerable#sort_by {|item| ... } -> [object] (6161.0)

ブロックの評価結果を <=> メソッドで比較することで、self を昇 順にソートします。ソートされた配列を新たに生成して返します。

...emlist[例][ruby]{
class Array
def sort_by
self.map {|i| [yield(i), i] }.
sort {|a, b| a[0] <=> b[0] }.
map {|i| i[1]}
end
end
//}

Enumerable#sort と比較して sort_by が優れている点として、
比較条件が複雑な場合の速度が挙げられます。
sort_by...
...ます。
従って downcase の実行速度が遅ければ sort の速度が致命的に低下します。

//emlist[][ruby]{
p ["BAR", "FOO", "bar", "foo"].sort {|a, b| a.downcase <=> b.downcase }
//}

一方、次のように sort_by を使うと downcase の実行回数は要素数と同じで...
...//emlist[][ruby]{
p ["BAR", "FOO", "bar", "foo"].sort_by {|v| v.downcase }
//}

以下の、実行回数の検証結果を参照してみてください。

//emlist[][ruby]{
class Integer
def count
$
n += 1
self
end
end

ary = []
1.upto(1000) {|v| ary << rand(v) }

$
n = 0
ary.sort {|a,b|...
<< 1 2 3 ... > >>