るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

キーワード

検索結果

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

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

...数える文字のパターン

//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 (55.0)

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

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

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

//emlist[例][ruby]{
class NegationRecorder < BasicObject
def initialize
@count = 0
end
att...
...!
@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

# another_falseは**
puts "...

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

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

...all メソッドを持ったオブジェクト。

//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('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#>>...

Resolv::DNS#timeouts=(values) (31.0)

DNSリゾルバのタイムアウト時間を設定します。

...DNSリゾルバのタイムアウト時間を設定します。

//emlist[][ruby]{
dns.timeouts = 3
//}

@param values タイムアウト時間(秒)を数値か数値の配列で指定します。配列
を指定した場合は応答を受信するまでの再試行時のタイムア...
...ウト
時間も含めて順に設定します。nil を指定した場合はデフォル
ト値
([ 5, second = 5 * 2 / nameserver_count, 2 * second, 4 * second ])
を使用します。...

Method#arity -> Integer (25.0)

メソッドが受け付ける引数の数を返します。

...数を
受け付ける場合、-1 を返します。

//emlist[例][ruby]{
class C
def u; end
def v(a); end
def w(*a); end
def x(a, b); end
def y(a, b, *c); end
def z(a, b, *c, &d); end
end

c = C.new
p c.method(:u).arity #=> 0
p c.metho...
...d(:v).arity #=> 1
p c.method(:w).arity #=> -1
p c.method(:x).arity #=> 2
p c.method(:y).arity #=> -3
p c.method(:z).arity #=> -3

s = "xyz"
s.method(:size).arity #=> 0
s.method(:replace).arity #=> 1
s.method(:squeeze).arity #=> -1
s.method(:count).arity #=> -1
//}...

絞り込み条件を変える

UnboundMethod#arity -> Integer (25.0)

メソッドが受け付ける引数の数を返します。

...可変長引数を
受け付ける場合、-1 を返します。

//emlist[例][ruby]{
class C
def one; end
def two(a); end
def three(*a); end
def four(a, b); end
def five(a, b, *c); end
def six(a, b, *c, &d); end
end

p C.instance_method(:one).arity #=> 0
p C.instance_method(...
...).arity #=> 2
p C.instance_method(:five).arity #=> -3
p C.instance_method(:six).arity #=> -3


String.instance_method(:size).arity #=> 0
String.instance_method(:replace).arity #=> 1
String.instance_method(:squeeze).arity #=> -1
String.instance_method(:count).arity #=> -1
//}...