るりまサーチ

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

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. range end

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 > >>

Kernel.#String(arg) -> String (18243.0)

引数を文字列(String)に変換した結果を返します。

...引数を文字列(String)に変換した結果を返します。

arg.to_s を呼び出して文字列に変換します。
arg が文字列の場合、何もせず arg を返します。

@param arg 変換対象のオブジェクトです。
@raise TypeError to_s の返り値が文字列でなけ...
...れば発生します。

//emlist[例][ruby]{
class Foo
def to_s
"hogehoge"
end

end


arg = Foo.new
p String(arg) #=> "hogehoge"
//}

@see Object#to_s,String...

Kernel.#caller(range) -> [String] | nil (146.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...l.#raise,
Kernel.#caller_locations

//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end


def bar
foo
end


bar

#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-:13:in `<main>'"]
# []...
...+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end

end


def foo
p parse_caller(caller.first)
end


def bar
foo
p parse_caller(caller.first)
end


bar
p parse_caller(caller.first)

#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}

以下は...
...、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。

//emlist[例][ruby]{
$DEBUG = true

def debug(*args)
p [caller.first, *args] if $DEBUG
end


debug "debug information"

#=> ["-:7", "debug information"]
//}...

Kernel.#caller(start = 1) -> [String] | nil (146.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...l.#raise,
Kernel.#caller_locations

//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end


def bar
foo
end


bar

#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-:13:in `<main>'"]
# []...
...+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end

end


def foo
p parse_caller(caller.first)
end


def bar
foo
p parse_caller(caller.first)
end


bar
p parse_caller(caller.first)

#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}

以下は...
...、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。

//emlist[例][ruby]{
$DEBUG = true

def debug(*args)
p [caller.first, *args] if $DEBUG
end


debug "debug information"

#=> ["-:7", "debug information"]
//}...

Kernel.#caller(start, length) -> [String] | nil (146.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...l.#raise,
Kernel.#caller_locations

//emlist[例][ruby]{
def foo
p caller(0)
p caller(1)
p caller(2)
p caller(3)
p caller(4)
end


def bar
foo
end


bar

#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-:13:in `<main>'"]
# []...
...+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end

end


def foo
p parse_caller(caller.first)
end


def bar
foo
p parse_caller(caller.first)
end


bar
p parse_caller(caller.first)

#=> ["-", 15, "bar"]
# ["-", 19, nil]
# nil
//}

以下は...
...、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。

//emlist[例][ruby]{
$DEBUG = true

def debug(*args)
p [caller.first, *args] if $DEBUG
end


debug "debug information"

#=> ["-:7", "debug information"]
//}...

Readline.#readline(prompt = "", add_hist = false) -> String | nil (144.0)

prompt を出力し、ユーザからのキー入力を待ちます。 エンターキーの押下などでユーザが文字列を入力し終えると、 入力した文字列を返します。 このとき、add_hist が true であれば、入力した文字列を入力履歴に追加します。 何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、 ユーザからの入力がない場合は nil を返します。

...buf
end

rescue Interrupt
system("stty", stty_save)
exit
end


例: INTシグナルを捕捉して、端末状態を復帰する。

require 'readline'

stty_save = `stty -g`.chomp
trap("INT") { system "stty", stty_save; exit }

while buf = Readline.readline
p buf
end
...
...た、単に ^C を無視する方法もあります。

require 'readline'

trap("INT", "SIG_IGN")

while buf = Readline.readline
p buf
end


入力履歴 Readline::HISTORY を使用して、次のようなこともできます。

例: 空行や直前の入力と同じ内容は入力履...
...f

begin
if Readline::HISTORY[Readline::HISTORY.length-2] == buf
Readline::HISTORY.pop
end

rescue IndexError
end


# p Readline::HISTORY.to_a
print "-> ", buf, "\n"
end


@see Readline.vi_editing_mode、Readline.emacs_editing_mode、
Readline::HISTORY...

絞り込み条件を変える

JSON.#generate(object, state = nil) -> String (139.0)

与えられたオブジェクトを一行の JSON 形式の文字列に変換して返します。

...す。
: :space
a string that is put after, a : or , delimiter (default: '')
: :space_before
a string that is put before a : pair delimiter (default: '')
: :object_nl
a string that is put at the end of a JSON object (default: '')
: :array_nl
a string that is put at the end of a JSON array (d...

JSON.#unparse(object, state = nil) -> String (139.0)

与えられたオブジェクトを一行の JSON 形式の文字列に変換して返します。

...す。
: :space
a string that is put after, a : or , delimiter (default: '')
: :space_before
a string that is put before a : pair delimiter (default: '')
: :object_nl
a string that is put at the end of a JSON object (default: '')
: :array_nl
a string that is put at the end of a JSON array (d...

Kernel.#autoload?(const_name) -> String | nil (132.0)

const_name が Kernel.#autoload 設定されているか調べます。

...みなら nil を返します。

@param const_name 定数をString または Symbol で指定します。

//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
class Bar
end

end

# ----- end of /tmp/foo.rb ----

class Foo
end

p Foo.autoload?(:Bar) #=> nil
Foo.autoload :Bar, '/t...

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

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

...sprintf("%c", 'a') #=> "a"
//}

フラグ `-' と幅 の指定だけが意味を持ちます。

: s

文字列を出力します。

引数が String オブジェクトでなければ to_s メソッドにより文字列化
したものを引数として扱います。

: p

Object#inspect の...
...合に使
用します。
//emlist[][ruby]{
case ENV['LC_TIME']
when /^ja_JP/
fmt = "%1$d年%2$d月%3$d日"
else
fmt = "%2$02d/%03$2d/%1$02d"
end


p sprintf(fmt, 1, 4, 22) #=> "04/22/01"
//}
"*" の後に指定することで幅や
精度を引数で指定することもできます。
//emli...
<< 1 2 > >>