るりまサーチ

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

別のキーワード

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

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Array#count -> Integer (18148.0)

レシーバの要素数を返します。

...ブロックを評価して真になった要素の個数を
カウントして返します。

@
param item カウント対象となる値。

//emlist[例][ruby]{
ary = [1, 2, 4, 2.0]
ary.count # => 4
ary.count(2) # => 2
ary.count{|x|x%2==0} # => 3
//}

@
see Enumerable#count...

Array#count {|obj| ... } -> Integer (18148.0)

レシーバの要素数を返します。

...ブロックを評価して真になった要素の個数を
カウントして返します。

@
param item カウント対象となる値。

//emlist[例][ruby]{
ary = [1, 2, 4, 2.0]
ary.count # => 4
ary.count(2) # => 2
ary.count{|x|x%2==0} # => 3
//}

@
see Enumerable#count...

Array#count(item) -> Integer (18148.0)

レシーバの要素数を返します。

...ブロックを評価して真になった要素の個数を
カウントして返します。

@
param item カウント対象となる値。

//emlist[例][ruby]{
ary = [1, 2, 4, 2.0]
ary.count # => 4
ary.count(2) # => 2
ary.count{|x|x%2==0} # => 3
//}

@
see Enumerable#count...

Enumerable#count -> Integer (18148.0)

レシーバの要素数を返します。

...価して真になった要素の個数を
カウントして返します。

@
param item カウント対象となる値。

//emlist[例][ruby]{
enum = [1, 2, 4, 2].each
enum.count # => 4
enum.count(2) # => 2
enum.count{|x|x%2==0} # => 3
//}

@
see Array#count...

Enumerable#count {|obj| ... } -> Integer (18148.0)

レシーバの要素数を返します。

...価して真になった要素の個数を
カウントして返します。

@
param item カウント対象となる値。

//emlist[例][ruby]{
enum = [1, 2, 4, 2].each
enum.count # => 4
enum.count(2) # => 2
enum.count{|x|x%2==0} # => 3
//}

@
see Array#count...

絞り込み条件を変える

Enumerable#count(item) -> Integer (18148.0)

レシーバの要素数を返します。

...価して真になった要素の個数を
カウントして返します。

@
param item カウント対象となる値。

//emlist[例][ruby]{
enum = [1, 2, 4, 2].each
enum.count # => 4
enum.count(2) # => 2
enum.count{|x|x%2==0} # => 3
//}

@
see Array#count...

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

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

...す。

@
param chars 出現回数を数える文字のパターン

//emlist[例][ruby]{
p 'abcdefg'.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 行として数えてしまうのでダメ
//}...

BasicObject#! -> bool (63.0)

オブジェクトを真偽値として評価し、その論理否定を返します。

...義しても Ruby の制御式において nil や false 以外が偽として
扱われることはありません。

@
return オブジェクトが偽であれば真、そうでない場合は偽

//emlist[例][ruby]{
class NegationRecorder < BasicObject
def initialize
@
count = 0
end
att...
...r_reader :count

def !
@
count += 1
super
end
end

recorder = NegationRecorder.new
!recorder
!!!!!!!recorder
puts 'hoge' if !recorder

puts recorder.count #=> 3
//}

//emlist[例][ruby]{
class AnotherFalse < BasicObject
def !
true
end
end
another_false = AnotherFalse.new

# anoth...

Enumerable#sort_by -> Enumerator (63.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#...
...//emlist[][ruby]{
p ["BAR", "FOO", "bar", "foo"].sort {|a, b| a.downcase <=> b.downcase }
//}

一方、次のように sort_by を使うと downcase の実行回数は要素数と同じです。
つまり、その部分の実行時間は O(n) のオーダーです。

//emlist[][ruby]{
p ["BAR",...
...照してみてください。

//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| a.count <=> b.count }
p $n # => 18200

$n = 0
ary.sort_by {|v| v.count }
p $n # => 1000
//}

Enumerable#so...
<< 1 2 > >>