るりまサーチ (Ruby 2.1.0)

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

別のキーワード

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

モジュール

キーワード

検索結果

NameError#to_s -> String (78364.0)

例外オブジェクトを文字列に変換して返します。

例外オブジェクトを文字列に変換して返します。

例:

begin
foobar
rescue NameError => err
p err # => #<NameError: undefined local variable or method `foobar' for main:Object>
p err.to_s # => "undefined local variable or method `foobar' for main:Object"
end

Thread::Backtrace::Location#to_s -> String (78364.0)

self が表すフレームを Kernel.#caller と同じ表現にした文字列を返し ます。

self が表すフレームを Kernel.#caller と同じ表現にした文字列を返し
ます。

//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.to_s
end

# => path/to/foo.rb:5:in `initialize'
# path/to/foo...

Thread::Backtrace::Location (24133.0)

Ruby のフレームを表すクラスです。

Ruby のフレームを表すクラスです。

Kernel.#caller_locations から生成されます。

//emlist[例1][ruby]{
# caller_locations.rb
def a(skip)
caller_locations(skip)
end
def b(skip)
a(skip)
end
def c(skip)
b(skip)
end

c(0..2).map do |call|
puts call.to_s
end
//}

例1の実行結果:

caller_locations.rb:2:in `a'
caller_locations...

Thread::Backtrace::Location#inspect -> String (24091.0)

Thread::Backtrace::Location#to_s の結果を人間が読みやすいような文 字列に変換したオブジェクトを返します。

Thread::Backtrace::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 ...

Kernel.#format(format, *arg) -> String (24043.0)

format 文字列を C 言語の sprintf と同じように解釈し、 引数をフォーマットした文字列を返します。

format 文字列を C 言語の sprintf と同じように解釈し、
引数をフォーマットした文字列を返します。

@param format フォーマット文字列です。
@param arg フォーマットされる引数です。
@see Kernel.#printf,Time#strftime,Date.strptime

=== sprintf フォーマット

Ruby の sprintf フォーマットは基本的に C 言語の sprintf(3)
のものと同じです。ただし、short や long などの C 特有の型に対する修飾子が
ないこと、2進数の指示子(%b, %B)が存在すること、s...

絞り込み条件を変える

Kernel.#sprintf(format, *arg) -> String (24043.0)

format 文字列を C 言語の sprintf と同じように解釈し、 引数をフォーマットした文字列を返します。

format 文字列を C 言語の sprintf と同じように解釈し、
引数をフォーマットした文字列を返します。

@param format フォーマット文字列です。
@param arg フォーマットされる引数です。
@see Kernel.#printf,Time#strftime,Date.strptime

=== sprintf フォーマット

Ruby の sprintf フォーマットは基本的に C 言語の sprintf(3)
のものと同じです。ただし、short や long などの C 特有の型に対する修飾子が
ないこと、2進数の指示子(%b, %B)が存在すること、s...

String#%(args) -> String (24043.0)

printf と同じ規則に従って args をフォーマットします。

printf と同じ規則に従って args をフォーマットします。

args が配列であれば Kernel.#sprintf(self, *args) と同じです。
それ以外の場合は Kernel.#sprintf(self, args) と同じです。

@param args フォーマットする値、もしくはその配列
@return フォーマットされた文字列

//emlist[例][ruby]{
p "i = %d" % 10 # => "i = 10"
p "i = %x" % 10 # => "i = a"
p "i = %o" % 10...

Symbol (24043.0)

シンボルを表すクラス。シンボルは任意の文字列と一対一に対応するオブジェクトです。

シンボルを表すクラス。シンボルは任意の文字列と一対一に対応するオブジェクトです。

文字列の代わりに用いることもできますが、必ずしも文字列と同じ振る舞いをするわけではありません。
同じ内容のシンボルはかならず同一のオブジェクトです。

シンボルオブジェクトは以下のようなリテラルで得られます。

:symbol
:'symbol'
%s!symbol! # %記法

生成されたシンボルの一覧は Symbol.all_symbols で得られます。
一番目のリテラルでシンボルを表す場合、`:' の後に
は識別子、メソッド名(`!',`?',`=' などの接尾辞を含む)、変数名
(`$'...