ライブラリ
- ビルトイン (324)
-
irb
/ cmd / help (11) -
irb
/ cmd / subirb (11) -
json
/ add / exception (11) - mkmf (22)
- timeout (11)
クラス
- Data (4)
- Exception (40)
-
IRB
:: ExtendCommand :: Help (11) -
IRB
:: ExtendCommand :: IrbCommand (11) - Module (18)
- NameError (11)
- Object (11)
-
RubyVM
:: InstructionSequence (44) - Struct (14)
- Thread (22)
-
Thread
:: Backtrace :: Location (33) - TracePoint (6)
モジュール
- Kernel (110)
オブジェクト
- main (11)
キーワード
- Error (11)
- Fiber (11)
- Location (11)
-
NEWS for Ruby 2
. 1 . 0 (11) -
NEWS for Ruby 2
. 7 . 0 (5) - Ruby用語集 (11)
-
at
_ exit (11) - autoload (7)
-
backtrace
_ locations (11) -
base
_ label (22) - caller (33)
-
caller
_ locations (22) - define (4)
- disasm (11)
- disassemble (11)
- execute (22)
- gets (11)
- inspect (11)
-
instruction
_ sequence (6) - irb (11)
- label (11)
- logger (11)
- new (14)
- pass (11)
- raise (11)
- rdoc (11)
- readline (11)
- refine (11)
-
respond
_ to? (11) -
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 3 feature (11) -
ruby 1
. 9 feature (11) -
set
_ backtrace (11) -
to
_ json (11) -
to
_ s (22) -
try
_ link (22) - using (11)
検索結果
先頭5件
-
main (44042.0)
-
トップレベルでの self を表すオブジェクトです。
...ェクトです。
main では参照できない事に注意してください。トップレベルで self から参照してください。
トップレベルで定義したメソッドは Object の private インスタンスメソッドと
して定義されます。
//emlist[例: トップ......basic_private_methods = private_methods(false)
basic_public_methods = public_methods(false)
private def explicit_private_method
end
# トップレベルで定義したメソッドは main オブジェクトの private メソッドと して定義される
def implicit_private_method
end
public de......f explicit_public_method
end
# main オブジェクトで独自定義した private method のみを取得する
p private_methods(false) - basic_private_methods
# => [:explicit_private_method, :implicit_private_method]
# main オブジェクトで独自定義した public method のみを取得... -
main
. using(module) -> self (30118.0) -
引数で指定したモジュールで定義された拡張を有効にします。
...inements_rdoc.html#label-Scope
@param module 有効にするモジュールを指定します。
//emlist[例][ruby]{
module Sloth
refine String do
def downcase
self
end
end
end
"ABC".downcase # => "abc"
using Sloth
"ABC".downcase # => "ABC"
//}
@see Module#refine, Module#usi... -
irb (26504.0)
-
irb は Interactive Ruby の略です。 irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
...irb は Interactive Ruby の略です。
irb を使うと、Ruby の式を標準入力から簡単に入力・実行することができます。
=== irb の使い方
Ruby さえ知っていれば irb を使うのは簡単です。
irb コマンドを実行すると、以下のようなプロン......$ irb
irb(main):001:0>
あとは Ruby の式を入力するだけで、その式が実行され、結果が表示されます。
irb(main):001:0> 1+2
3
irb(main):002:0> class Foo
irb(main):003:1> def foo
irb(main):004:2> print 1
irb(main):005:2> end
irb(main):006:1> end......:foo
irb(main):007:0>
また irb コマンドは readline ライブラリにも対応しています。
readline ライブラリがインストールされている時には
自動的にコマンドライン編集や履歴の機能が使えるようになります。
=== irb のコマンドラ... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (9230.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
...ception#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。
現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。
//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if D......aise "#{month} is not long month"
end
def get_exception
return begin
yield
rescue => e
e
end
end
e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_exception'", "test.rb:15:i......n `<main>'"]
//}
@see Exception#backtrace... -
TracePoint
# instruction _ sequence -> RubyVM :: InstructionSequence (9218.0) -
script_compiledイベント発生時にコンパイルされた RubyVM::InstructionSequenceインスタンスを返します。
...script_compiledイベント発生時にコンパイルされた
RubyVM::InstructionSequenceインスタンスを返します。
//emlist[例][ruby]{
TracePoint.new(:script_compiled) do |tp|
p tp.instruction_sequence # => <RubyVM::InstructionSequence:block in <main>@(eval):1>
end.enable do
eval......("puts 'hello'")
end
//}
@raise RuntimeError :script_compiled イベントのための
イベントフックの外側で実行した場合に発生します。... -
IRB
:: ExtendCommand :: IrbCommand # execute(*obj) -> IRB :: Irb (9206.0) -
新しいサブ irb インタプリタを起動します。
...新しいサブ irb インタプリタを起動します。
@param obj 新しいサブ irb インタプリタで self にするオブジェクトを指定
します。省略した場合は irb を起動したときの main オブジェク
トを self にします。... -
Kernel
. # caller _ locations(range) -> [Thread :: Backtrace :: Location] | nil (6224.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...現在のフレームを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。
@param start 開始フレームの位置を数値で指定します。
@param length 取得するフレームの個数を指定します。
@pa......。
//emlist[例][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)
test1(start, length)
end
def test3(start, length)
test2(start, length)
end
caller_locations # => []......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"]
test3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `t... -
Kernel
. # caller _ locations(start = 1 , length = nil) -> [Thread :: Backtrace :: Location] | nil (6224.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...現在のフレームを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。
@param start 開始フレームの位置を数値で指定します。
@param length 取得するフレームの個数を指定します。
@pa......。
//emlist[例][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)
test1(start, length)
end
def test3(start, length)
test2(start, length)
end
caller_locations # => []......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"]
test3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `t... -
Thread
:: Backtrace :: Location # inspect -> String (6224.0) -
Thread::Backtrace::Location#to_s の結果を人間が読みやすいような文 字列に変換したオブジェクトを返します。
...race::Location#to_s の結果を人間が読みやすいような文
字列に変換したオブジェクトを返します。
//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end
Foo.new(0..2).locations.map do......|call|
puts call.inspect
end
# => "path/to/foo.rb:5:in `initialize'"
# "path/to/foo.rb:9:in `new'"
# "path/to/foo.rb:9:in `<main>'"
//}... -
Kernel
. # readline(rs = $ / ) -> String (6212.0) -
ARGFから一行読み込んで、それを返します。 行の区切りは引数 rs で指定した文字列になります。
...ARGFから一行読み込んで、それを返します。
行の区切りは引数 rs で指定した文字列になります。
rs に nil を指定すると行区切りなしとみなしてファイルの内容を
すべて読み込みます。ARGVに複数のファイル名が存在する場......@raise Errno::EXXX 読み込みに失敗した場合に発生します。
@raise EOFError readline でファイル末端(EOF)を検出すると発生します。
//emlist[例][ruby]{
# ---main.rb---
ARGV << 'b.txt' << 'c.txt'
p readline #=> "hello\n"
p readline(nil) #=> "it\ncommon\n"
p readline("......"ARGF\n\n"
p readline('、') #=> "スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と\nみなして、"
p readline #=> "それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。 \n"
p readline # end of file reached (EOFErr...