るりまサーチ

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Kernel.#require(feature) -> bool (32227.0)

Ruby ライブラリ feature をロードします。拡張子補完を行い、 同じファイルの複数回ロードはしません。

...字列です。
@raise LoadError ロードに失敗した場合に発生します。

//emlist[例][ruby]{
$LOADED_FEATURES.grep(/prime/).size # => 0
require
"prime" # => true
$LOADED_FEATURES.grep(/prime/).size # => 1
require
"prime" # => 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 (20249.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=1> (NameError)...

Exception#backtrace_locations -> [Thread::Backtrace::Location] (17208.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...

Binding#irb -> object (17108.0)

REPLのセッションを開始します。

...REPLのセッションを開始します。

2.5.0 からは require 'irb' せずに直接 binding.irb を呼び出しても使えるようになりました。

@see irb...

RubyVM::InstructionSequence#first_lineno -> Integer (17108.0)

self が表す命令シーケンスの 1 行目の行番号を返します。

...の 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(method(:foo)).first_lineno
# => 2...

絞り込み条件を変える

Enumerable#each_with_index(*args) {|item, index| ... } -> self (14220.0)

要素とそのインデックスをブロックに渡して繰り返します。

...with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのまま渡されます。

//emlist[例][ruby]{
[5, 10, 15].each_wit...
...h_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}

//emlist[引数ありの例][ruby]{
require
'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}

@see Enumerator#with_index...

Kernel$$-I -> [String] (14145.0)

Rubyライブラリをロードするときの検索パスです。

...です。

Kernel.#load や Kernel.#require
がファイルをロードする時に検索するディレクトリのリストを含む配列です。

起動時にはコマンドラインオプション -I で指定したディレクトリ、
環境変数 RUBYLIB の値、
コンパイル時に指...
...下に典型的な UNIX システム上でのロードパスを示します。

-I で指定したパス
環境変数 RUBYLIB の値
/usr/local/lib/ruby/site_ruby/VERSION サイト固有、バージョン依存のライブラリ
/usr/local/lib/ruby/site_ruby/VERSION/ARCH サイト...
...ラリ
/usr/local/lib/ruby/site_ruby サイト固有ライブラリ
/usr/local/lib/ruby/VERSION 標準ライブラリ
/usr/local/lib/ruby/VERSION/ARCH 標準、システム依存、拡張ライブラリ

上記表中の VERSION は Ruby のバージ...

Enumerable#each_with_index(*args) -> Enumerator (14120.0)

要素とそのインデックスをブロックに渡して繰り返します。

...with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのまま渡されます。

//emlist[例][ruby]{
[5, 10, 15].each_wit...
...h_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}

//emlist[引数ありの例][ruby]{
require
'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}

@see Enumerator#with_index...

Enumerator#with_index(offset = 0) -> Enumerator (14120.0)

生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。

...す。

//emlist[例][ruby]{
str = "xyz"

enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]

require
"stringio"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["f...
...にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。...

Enumerator#with_index(offset = 0) {|(*args), idx| ... } -> object (14120.0)

生成時のパラメータに従って、要素にインデックスを添えて繰り返します。 インデックスは offset から始まります。

...す。

//emlist[例][ruby]{
str = "xyz"

enum = Enumerator.new {|y| str.each_byte {|b| y << b }}
enum.with_index {|byte, idx| p [byte, idx] }
# => [120, 0]
# [121, 1]
# [122, 2]

require
"stringio"
StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }
# => ["f...
...にインデックスを添えてブロックを繰り返します。
インデックスは 0 から始まります。
Enumerator#with_index は offset 引数を受け取りますが、
each_with_index は受け取りません (引数はイテレータメソッドにそのまま渡されます)。...

絞り込み条件を変える

<< 1 2 3 ... > >>