種類
- モジュール関数 (84)
- インスタンスメソッド (72)
ライブラリ
- ビルトイン (156)
クラス
- BasicObject (22)
- Integer (22)
- Object (11)
- Proc (6)
- Regexp (11)
モジュール
- Kernel (84)
検索結果
先頭5件
-
BasicObject
# ! -> bool (26143.0) -
オブジェクトを真偽値として評価し、その論理否定を返します。
...f !
@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... -
Kernel
. # exit!(status = false) -> () (14136.0) -
Rubyプログラムの実行を即座に終了します。 status として整数が与えられた場合、その値を Ruby コマンドの終了ステータスとします。 デフォルトの終了ステータスは 1 です。
...定したとみなされます。この値はCレベルの定数
EXIT_SUCCESS、EXIT_FAILURE の値なので、正確には環境依存です。
exit! は exit とは違って、例外処理などは一切行ないませ
ん。 Kernel.#fork の後、子プロセスを終了させる時などに用......与えます。
//emlist[例][ruby]{
STDOUT.sync = true #表示前に終了しないようにする
puts 'start'
begin
puts 'start1...'
exit!
ensure
puts 'end1...' #実行されない
end
puts 'end' #実行されない
#=> start
# start1...
#終了ステータス:1
//}
@see Kernel.#exit,K... -
BasicObject
# !=(other) -> bool (14106.0) -
オブジェクトが other と等しくないことを判定します。
...返します。
このため、サブクラスで BasicObject#== を再定義しても != とは自動的に整合性が
とれるようになっています。
ただし、 BasicObject#!= 自身や BasicObject#! を再定義した際には、ユーザーの責任で
整合性を保たなくては......icObject#==, BasicObject#!
//emlist[例][ruby]{
class NonequalityRecorder < BasicObject
def initialize
@count = 0
end
attr_reader :count
def !=(other)
@count += 1
super
end
end
recorder = NonequalityRecorder.new
recorder != 1
puts 'hoge' if recorder != "str"
p recorder.coun... -
Object
# ===(other) -> bool (8036.0) -
case 式で使用されるメソッドです。d:spec/control#case も参照してください。
..."youth"
else
"adult"
end
puts result #=> "child"
def check arg
case arg
when /ruby(?!\s*on\s*rails)/i
"hit! #{arg}"
when String
"Instance of String class. But don't hit."
else
"unknown"
end
end
puts check([]) #=> unknown
puts check("mash-up in Ruby on Rails") #=......> instance of String class. But not hit...
puts check("<Ruby's world>") #=> hit! <Ruby's world>
//}
@see Object#==, Range#===, Module#===, Regexp#===, Enumerable#grep... -
Kernel
. # warn(*message , uplevel: nil , category: nil) -> nil (8024.0) -
message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。
...出力します。
uplevel を指定しない場合は、
このメソッドは以下と同じです。
//emlist[][ruby]{
$stderr.puts(*message) if !$VERBOSE.nil? && !message.empty?
nil
//}
@param message 出力するオブジェクトを任意個指定します。
@param uplevel いくつ前の......れば発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
//emlist[例][ruby]{
warn "caution!" #=> caution!
$VERBOSE = nil
warn "caution!" # 何もしない
//}
//emlist[uplevel の例][ruby]{
def foo
warn("test message", uplevel: 0) # => test.rb:2: warning: te......y]{
Warning[:deprecated] = true # 非推奨の警告を表示する
warn("deprecated!!", category: :deprecated)
# => deprecated!
Warning[:deprecated] = false # 非推奨の警告を表示しない
warn("deprecated!!", category: :deprecated)
# 警告は出力されない
//}
@see Warning#warn, $std... -
Integer
# times -> Enumerator (8018.0) -
self 回だけ繰り返します。 self が正の整数でない場合は何もしません。
...ータには 0 から self - 1 までの数値が渡されます。
//emlist[][ruby]{
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。... -
Integer
# times {|n| . . . } -> self (8018.0) -
self 回だけ繰り返します。 self が正の整数でない場合は何もしません。
...ータには 0 から self - 1 までの数値が渡されます。
//emlist[][ruby]{
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。... -
Kernel
. # warn(*message) -> nil (8018.0) -
message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。
...により文字列に変換してから出力します。
このメソッドは以下と同じです。
//emlist[][ruby]{
$stderr.puts(*message) if !$VERBOSE.nil? && !message.empty?
nil
//}
@param message 出力するオブジェクトを任意個指定します。
@raise IOError 標準エラー......出力が書き込み用にオープンされていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
//emlist[例][ruby]{
warn "caution!" #=> caution!
$VERBOSE = nil
warn "caution!" # 何もしない
//}
@see $stderr,$VERBOSE......出力が書き込み用にオープンされていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
//emlist[例][ruby]{
warn "caution!" #=> caution!
$VERBOSE = nil
warn "caution!" # 何もしない
//}
@see Warning#warn, $stderr,$VERBOSE... -
Kernel
. # warn(*message , uplevel: nil) -> nil (8018.0) -
message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。
...出力します。
uplevel を指定しない場合は、
このメソッドは以下と同じです。
//emlist[][ruby]{
$stderr.puts(*message) if !$VERBOSE.nil? && !message.empty?
nil
//}
@param message 出力するオブジェクトを任意個指定します。
@param uplevel いくつ前の......れば発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
//emlist[例][ruby]{
warn "caution!" #=> caution!
$VERBOSE = nil
warn "caution!" # 何もしない
//}
//emlist[uplevel の例][ruby]{
def foo
warn("test message", uplevel: 0) # => test.rb:2: warning: te... -
Proc
# <<(callable) -> Proc (8018.0) -
self と引数を合成した Proc を返します。
...[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 Me... -
Kernel
. # loop -> Enumerator (8012.0) -
(中断されない限り)永遠にブロックの評価を繰り返します。 ブロックが指定されなければ、代わりに Enumerator を返します。
...クが指定されなければ、代わりに Enumerator を返します。
//emlist[例][ruby]{
loop do
print "Input: "
line = gets
break if !line or line =~ /^qQ/
# ...
end
//}
与えられたブロック内で StopIteration を Kernel.#raise すると
ループを終了して Enumerator......。
ループを終了させる場合、通常は break を使用してください。
//emlist[例][ruby]{
enum = Enumerator.new { |y|
y << "one"
y << "two"
:ok
}
result = loop {
puts enum.next
} # => :ok
//}
@return break の引数など、ループ脱出時の値を返します。... -
Kernel
. # loop { . . . } -> object | nil (8012.0) -
(中断されない限り)永遠にブロックの評価を繰り返します。 ブロックが指定されなければ、代わりに Enumerator を返します。
...クが指定されなければ、代わりに Enumerator を返します。
//emlist[例][ruby]{
loop do
print "Input: "
line = gets
break if !line or line =~ /^qQ/
# ...
end
//}
与えられたブロック内で StopIteration を Kernel.#raise すると
ループを終了して Enumerator......。
ループを終了させる場合、通常は break を使用してください。
//emlist[例][ruby]{
enum = Enumerator.new { |y|
y << "one"
y << "two"
:ok
}
result = loop {
puts enum.next
} # => :ok
//}
@return break の引数など、ループ脱出時の値を返します。...