クラス
- Array (19)
- Dir (52)
- Enumerator (5)
- Exception (22)
- File (11)
-
File
:: Stat (33) - IO (22)
- LoadError (11)
- Method (11)
- Module (11)
- Object (36)
- Random (22)
- Range (11)
-
RubyVM
:: InstructionSequence (22) - String (22)
- Thread (11)
-
Thread
:: Queue (9) -
Thread
:: SizedQueue (27) - Time (10)
- UnboundMethod (11)
モジュール
- Enumerable (66)
- FileTest (44)
- Kernel (99)
キーワード
-
$ " (11) -
$ -I (11) -
$ : (11) -
$ LOADED _ FEATURES (11) -
$ LOAD _ PATH (11) - <=> (11)
- == (11)
- ConditionVariable (9)
- DATA (11)
-
SCRIPT
_ LINES _ _ (11) - SizedQueue (9)
- all? (11)
- any? (11)
- autoload (22)
-
backtrace
_ locations (11) - ceil (5)
-
compile
_ option (11) - crypt (11)
- deq (9)
-
each
_ with _ index (22) - empty? (8)
- entries (11)
- fcntl (11)
-
first
_ lineno (11) - floor (5)
- flush (11)
-
handle
_ interrupt (11) - load (11)
- new (22)
- open (22)
- pack (19)
- path (22)
- pop (9)
- produce (5)
- rand (22)
- read (11)
-
require
_ relative (11) - setgid? (11)
- setuid? (11)
- shift (18)
- size? (11)
- socket? (11)
-
source
_ location (22) - sticky? (11)
- symlink? (11)
-
to
_ a (11) - unpack (11)
-
yield
_ self (14)
検索結果
先頭5件
-
Kernel
. # require(feature) -> bool (27327.0) -
Ruby ライブラリ feature をロードします。拡張子補完を行い、 同じファイルの複数回ロードはしません。
...のホームディレクトリに展開されます。
Ruby ライブラリとは Ruby スクリプト (*.rb) か拡張ライブラリ
(*.so,*.o,*.dll など) であり、feature の拡張子が省略された場合はその
両方から探します( *.rb が優先されます)。
省略されな......false を返します。
@param feature ファイル名の文字列です。
@raise LoadError ロードに失敗した場合に発生します。
//emlist[例][ruby]{
$LOADED_FEATURES.grep(/prime/).size # => 0
require "prime" # => true
$LOADED_FEATURES.grep(/prime/).size # => 1
require "prim......e" # => false
begin
require "invalid"
rescue LoadError => e
e.message # => "cannot load such file -- invalid"
end
//}
@see Kernel.#load,Kernel.#autoload,Kernel.#require_relative... -
Kernel
. # require _ relative(relative _ feature) -> bool (18449.0) -
現在のファイルからの相対パスで require します。
...の相対パスで require します。
require File.expand_path(relative_feature, File.dirname(__FILE__))
とほぼ同じです。
Kernel.#eval などで文字列を評価した場合に、そこから
require_relative を呼出すと必ず失敗します。
@param relative_feature ファイ......ル名の文字列です。
@raise LoadError ロードに失敗した場合に発生します。
@see Kernel.#require
=== require と load のスコープ
ローカル変数はファイル間では共有されません。ですので、
ロードしたライブラリのローカル変数を
ロー......このスコープの扱い方はKernel.#loadでも同様です。
//emlist[例][ruby]{
# ---------- some.rb -----------
$a = 1
@a = 1
A = 1
a = 1
# ---------- end some.rb -------
require 'some'
p $a #=> 1
p @a #=> 1
p A #=> 1
p a # undefined local variable or method `a' for #<Object:0x294f9ec @a... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (15408.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... -
RubyVM
:: InstructionSequence # first _ lineno -> Integer (15208.0) -
self が表す命令シーケンスの 1 行目の行番号を返します。
...self が表す命令シーケンスの 1 行目の行番号を返します。
例1:irb で実行した場合
RubyVM::InstructionSequence.compile('num = 1 + 2').first_lineno
# => 1
例2:
# /tmp/method.rb
require "foo-library"
def foo
p :foo
end
RubyVM::InstructionSequence.of(m......ethod(:foo)).first_lineno
# => 2... -
Object
# yield _ self -> Enumerator (12214.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
"my string".yield_self {|s| s.upcase } # => "MY STRING"
3.next.yield_self {|x| x**x }.to_s # => "256"
//}
値をメソッドチェインのパイプラインに次々と渡すの......は良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerat......返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
# yield _ self {|x| . . . } -> object (12214.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
"my string".yield_self {|s| s.upcase } # => "MY STRING"
3.next.yield_self {|x| x**x }.to_s # => "256"
//}
値をメソッドチェインのパイプラインに次々と渡すの......は良い使い方です。
//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerat......返します。
例えば条件によって値を捨てるのに使えます。
//emlist[][ruby]{
# 条件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}
@see Object#tap... -
Object
:: SCRIPT _ LINES _ _ -> Hash (12214.0) -
ソースファイル別にまとめられたソースコードの各行。
...Kernel.#eval によるコンパイルは対象にはなりません。
例:
require 'pp'
SCRIPT_LINES__ = {}
require 'English'
pp SCRIPT_LINES__
# => {"/usr/local/lib/ruby/1.6/English.rb"=>
# ["alias $ERROR_INFO $!\n",
# "alias $ERROR_POSITION......$@\n",
# "alias $LOADED_FEATURES $\"\n",
# :
# :
# "alias $POSTMATCH $'\n",
# "alias $LAST_PAREN_MATCH $+\n"]}... -
File
:: Stat # symlink? -> false (12208.0) -
シンボリックリンクである時に真を返します。 ただし、File::Statは自動的にシンボリックリンクをたどっていくので 常にfalseを返します。
...、File::Statは自動的にシンボリックリンクをたどっていくので
常にfalseを返します。
//emlist[][ruby]{
require 'fileutils'
outfile = $0 + ".ln"
FileUtils.ln_s($0, outfile)
p File::Stat.new(outfile).symlink? #=> false
p File.lstat(outfile).symlink? #=> true
p FileTest.......symlink?(outfile) #=> true
//}
@see File.lstat... -
Method
# source _ location -> [String , Integer] | nil (12208.0) -
ソースコードのファイル名と行番号を配列で返します。
...nil を返します。
@see Proc#source_location
//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
def foo; end
end
# ----- end of /tmp/foo.rb ----
require '/tmp/foo'
m = Foo.new.method(:foo) # => #<Method: Foo#foo>
m.source_location # => ["/tmp/foo.rb", 2]
method(:puts).source_l......ocation # => nil
//}... -
RubyVM
:: InstructionSequence . compile _ option -> Hash (12208.0) -
命令シーケンスのコンパイル時のデフォルトの最適化オプションを Hash で返 します。
...emlist[例][ruby]{
require "pp"
pp RubyVM::InstructionSequence.compile_option
# => {:inline_const_cache=>true,
# :peephole_optimization=>true,
# :tailcall_optimization=>false,
# :specialized_instruction=>true,
# :operands_unification=>true,
# :instructions_unification=>false,
# :stack_caching=>fals......e,
# :trace_instruction=>true,
# :frozen_string_literal=>false,
# :debug_frozen_string_literal=>false,
# :coverage_enabled=>true,
# :debug_level=>0}
//}
@see RubyVM::InstructionSequence.compile_option=... -
Thread
. handle _ interrupt(hash) { . . . } -> object (12208.0) -
スレッドの割り込みのタイミングを引数で指定した内容に変更してブロックを 実行します。
...#raise や
Thread#kill、Signal.#trap(未サポート)、メインスレッドの終了
(メインスレッドが終了すると、他のスレッドも終了されます)を意味します。
@param hash 例外クラスがキー、割り込みのタイミングを指定する
Symbol......が値の Hash を指定します。
値の内容は以下のいずれかです。
: :immediate
すぐに割り込みます。
: :on_blocking
ブロッキング処理(後述)の間は割り込みが発生します。
: :never
まったく割り込みません。
「ブロッ......味します。CRuby の実装では、GVL
を解放して実行する処理は全てブロッキング処理に含まれます。
また、マスクされた非同期割り込みは再度有効にされるまで延期されます。本
メソッドは sigprocmask(3) に似ています。
@return...