るりまサーチ

最速Rubyリファレンスマニュアル検索!
141件ヒット [1-100件を表示] (0.034秒)
トップページ > モジュール:Kernel[x] > クエリ:test[x] > ライブラリ:ビルトイン[x]

別のキーワード

  1. kernel test
  2. _builtin test
  3. rubygems/test_utilities tempio
  4. rubygems/test_utilities fetcher=
  5. validator unit_test

キーワード

検索結果

<< 1 2 > >>

Kernel.#test(cmd, file) -> bool | Time | Integer | nil (18132.0)

単体のファイルでファイルテストを行います。

...me
: ?A
ファイルの最終アクセス時刻を返す -> Time
: ?C
ファイルの inode 変更時刻を返す -> Time

//emlist[例][ruby]{
IO.write("testfile", "test")
test
("r", "testfile") # => true
test
("s", "testfile") # => 4
test
("M", "testfile") # => 2018-03-31 07:38:40 +0900
//}...

Kernel.#test(cmd, file1, file2) -> bool (18127.0)

2ファイル間のファイルテストを行います。

...ァイル1とファイル2が同一のファイルである

//emlist[例][ruby]{
IO.write("testfile1", "test1")
IO.write("testfile2", "test2")
%w(= < > -).each do |e|
result = test(e, "testfile1", "testfile2")
puts "#{e}: #{result}"
end
//}

# => =: true
# => <: false
# => >: false
# => -: fals...

Kernel.#caller_locations(range) -> [Thread::Backtrace::Location] | nil (153.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end

def test2(start, length)
test
1(start, length)
end

def test3(start, length)
test
2(start, length)
end

caller_locations # => []
test
3(1, nil)
#...
.../Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test
3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9...
..., 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test
3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}

@see Thread::Backtrace::Location, Kernel.#caller...

Kernel.#caller_locations(start = 1, length = nil) -> [Thread::Backtrace::Location] | nil (153.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end

def test2(start, length)
test
1(start, length)
end

def test3(start, length)
test
2(start, length)
end

caller_locations # => []
test
3(1, nil)
#...
.../Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test
3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9...
..., 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test
3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}

@see Thread::Backtrace::Location, Kernel.#caller...

Kernel.#chop -> String (51.0)

$_.chop とほぼ同じですが、置換が発生したときは、$_の内容を置き換える点が異なります。 コマンドラインオプションで -p または -n を指定した時のみ定義されます。

...コピーの方を更新し、
$_ に再代入します。

//emlist[例][ruby]{
$_ = "test\r\n"
$_ # => "test\r\n"
chop # => "test"
$_ = "test\n"
$_ # => "test\n"
chop # => "test"
$_ = "test"
$_ # => "test"
chop # => "tes"
//}

@see String#chop,$_...

絞り込み条件を変える

Kernel.#warn(*message, uplevel: nil) -> nil (51.0)

message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。

...
//}

//emlist[uplevel の例][ruby]{
def foo
warn("test message", uplevel: 0) # => test.rb:2: warning: test message
warn("test message", uplevel: 1) # => test.rb:6: warning: test message
warn("test message", uplevel: 2) # => test message
end
foo
//}


@see Warning#warn, $stderr,$VERBOSE...

Kernel.#warn(*message, uplevel: nil, category: nil) -> nil (51.0)

message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。

...
//}

//emlist[uplevel の例][ruby]{
def foo
warn("test message", uplevel: 0) # => test.rb:2: warning: test message
warn("test message", uplevel: 1) # => test.rb:6: warning: test message
warn("test message", uplevel: 2) # => test message
end
foo
//}

//emlist[category の例][ruby]{
Warnin...

Kernel.#chomp(rs = $/) -> String (45.0)

$_.chomp とほぼ同じですが、置換が発生したときは、$_の内容を置き換える点が異なります。 コマンドラインオプションで -p または -n を指定した時のみ定義されます。

...//emlist[例: ruby -n で "test" を入力][ruby]{
$_ # => "test\n"
chomp # => "test"
//}

//emlist[例: ruby -n で "test," を入力し、 rs に "," を指定][ruby]{
$_ # => "test\n"
chomp # => "test,"
chomp(",") # => "test"
//}

@see String#chomp,$_,$/...

Kernel.#lambda -> Proc (39.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...生します。][ruby]{
pr = Proc.new { break }
(1..5).each(&pr)
//}

===[a:lambda_proc] lambda と proc と Proc.new とイテレータの違い

Kernel
.#lambda と Proc.new はどちらも Proc クラスのインスタンス(手続きオブジェクト)を生成しますが、
生成された手...
...。 lambda の生成する手続きオブジェクトのほうが
よりメソッドに近い働きをするように設計されています。

Kernel
.#proc は Proc.new と同じになります。
引数に & を付けることで手続きオブジェクト化したブロックは、Proc.new で...
...ruby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap { return :from_block }
return :from_method
end

p test_proc() #=> :from_proc
p test_lambda()...

Kernel.#lambda { ... } -> Proc (39.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...生します。][ruby]{
pr = Proc.new { break }
(1..5).each(&pr)
//}

===[a:lambda_proc] lambda と proc と Proc.new とイテレータの違い

Kernel
.#lambda と Proc.new はどちらも Proc クラスのインスタンス(手続きオブジェクト)を生成しますが、
生成された手...
...。 lambda の生成する手続きオブジェクトのほうが
よりメソッドに近い働きをするように設計されています。

Kernel
.#proc は Proc.new と同じになります。
引数に & を付けることで手続きオブジェクト化したブロックは、Proc.new で...
...ruby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap { return :from_block }
return :from_method
end

p test_proc() #=> :from_proc
p test_lambda()...

絞り込み条件を変える

Kernel.#proc -> Proc (39.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...生します。][ruby]{
pr = Proc.new { break }
(1..5).each(&pr)
//}

===[a:lambda_proc] lambda と proc と Proc.new とイテレータの違い

Kernel
.#lambda と Proc.new はどちらも Proc クラスのインスタンス(手続きオブジェクト)を生成しますが、
生成された手...
...。 lambda の生成する手続きオブジェクトのほうが
よりメソッドに近い働きをするように設計されています。

Kernel
.#proc は Proc.new と同じになります。
引数に & を付けることで手続きオブジェクト化したブロックは、Proc.new で...
...ruby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap { return :from_block }
return :from_method
end

p test_proc() #=> :from_proc
p test_lambda()...

Kernel.#proc { ... } -> Proc (39.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...生します。][ruby]{
pr = Proc.new { break }
(1..5).each(&pr)
//}

===[a:lambda_proc] lambda と proc と Proc.new とイテレータの違い

Kernel
.#lambda と Proc.new はどちらも Proc クラスのインスタンス(手続きオブジェクト)を生成しますが、
生成された手...
...。 lambda の生成する手続きオブジェクトのほうが
よりメソッドに近い働きをするように設計されています。

Kernel
.#proc は Proc.new と同じになります。
引数に & を付けることで手続きオブジェクト化したブロックは、Proc.new で...
...ruby]{
def test_proc
f = Proc.new { return :from_proc }
f.call
return :from_method
end

def test_lambda
f = lambda { return :from_lambda }
f.call
return :from_method
end

def test_block
tap { return :from_block }
return :from_method
end

p test_proc() #=> :from_proc
p test_lambda()...
<< 1 2 > >>