るりまサーチ

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

別のキーワード

  1. stringio read
  2. _builtin read
  3. io read
  4. csv read
  5. tuple read

ライブラリ

クラス

キーワード

検索結果

String#count(*chars) -> Integer (18144.0)

chars で指定された文字が文字列 self にいくつあるか数えます。

...cdefg'.count('c') # => 1
p '123456789'.count('2378') # => 4
p '123456789'.count('2-8', '^4-6') # => 4

# ファイルの行数を数える
n_lines = File.read("foo").count("\n")

# ファイルの末尾に改行コードがない場合にも対処する
buf = File.read("foo"...
...)
n_lines = buf.count("\n")
n_lines += 1 if /[^\n]\z/ =~ buf
# if /\n\z/ !~ buf だと空ファイルを 1 行として数えてしまうのでダメ
//}...

CSV#read -> [Array] | CSV::Table (18132.0)

残りの行を読み込んで配列の配列を返します。 self の生成時に headers オプションに偽でない値が指定されていた場合は CSV::Table オブジェクトを返します。

...(DATA.read)
csv.read
# => [["header1", "header2"], ["row1_1", "row1_2"], ["row2_1", "row2_2"]]

__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}

//emlist[例 headers: true][ruby]{
require "csv"

csv = CSV.new(DATA.read, headers: true)
csv.read
# => #<CSV::Table mode:col_or_row row_count:3>...

CSV#readlines -> [Array] | CSV::Table (6132.0)

残りの行を読み込んで配列の配列を返します。 self の生成時に headers オプションに偽でない値が指定されていた場合は CSV::Table オブジェクトを返します。

...(DATA.read)
csv.read
# => [["header1", "header2"], ["row1_1", "row1_2"], ["row2_1", "row2_2"]]

__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}

//emlist[例 headers: true][ruby]{
require "csv"

csv = CSV.new(DATA.read, headers: true)
csv.read
# => #<CSV::Table mode:col_or_row row_count:3>...

Thread#priority -> Integer (3049.0)

スレッドの優先度を返します。この値が大きいほど優先度が高くなります。 メインスレッドのデフォルト値は 0 です。新しく生成されたスレッドは親スレッドの priority を引き継ぎます。

...ist[例][ruby]{
Thread.current.priority # => 0

count
1 = count2 = 0
a = Thread.new do
loop { count1 += 1 }
end
a.priority = -1

b = Thread.new do
loop { count2 += 1 }
end
b.priority = -2
count
1 = count2 = 0 # reset
sleep 1 # => 1
count
1 # => 13809431
count
2 # => 1157192...

Thread#priority=(val) (3049.0)

スレッドの優先度を返します。この値が大きいほど優先度が高くなります。 メインスレッドのデフォルト値は 0 です。新しく生成されたスレッドは親スレッドの priority を引き継ぎます。

...ist[例][ruby]{
Thread.current.priority # => 0

count
1 = count2 = 0
a = Thread.new do
loop { count1 += 1 }
end
a.priority = -1

b = Thread.new do
loop { count2 += 1 }
end
b.priority = -2
count
1 = count2 = 0 # reset
sleep 1 # => 1
count
1 # => 13809431
count
2 # => 1157192...

絞り込み条件を変える

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

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

...anner
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#>>...

CSV::Table#inspect -> String (13.0)

モードとサイズを US-ASCII な文字列で返します。

...モードとサイズを US-ASCII な文字列で返します。

//emlist[][ruby]{
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
p table.inspect # => "#<CSV::Table mode:col_or_row row_count:2>"
//}...