るりまサーチ

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

別のキーワード

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

クラス

モジュール

キーワード

検索結果

Kernel.#puts(*arg) -> nil (26151.0)

引数と改行を順番に 標準出力 $stdout に出力します。 引数がなければ改行のみを出力します。

...は、
当該オブジェクトを最初に to_ary により配列へ、
次に to_s メソッドにより文字列へ変換を試みます。
末尾が改行で終っている引数や配列の要素に対しては puts 自身
は改行を出力しません。

@param arg 出力するオブジェ...
...に失敗した場合に発生します。

//emlist[例][ruby]{
puts
"foo", "bar\n", "baz"
puts
"" # 改行のみ出力
puts
# 改行のみ出力
puts
nil # 改行のみ出力
puts
["oui", "non"]
#=> foo
# bar
# baz
#
#
#
# oui
# non
//}

@see Kernel.#print, Kernel.#p, IO#puts...

Object#to_s -> String (26121.0)

オブジェクトの文字列表現を返します。

...使って文字列に変換し
ます。

//emlist[][ruby]{
class Foo
def initialize num
@num = num
end
end
it = Foo.new(40)

puts
it #=> #<Foo:0x2b69110>

class Foo
def to_s
"Class:Foo Number:#{@num}"
end
end

puts
it #=> Class:Foo Number:40
//}

@see Object#to_str,Kernel.#String...

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

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

...mlist[例][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.rb:9:in `new'
# path/to/foo.rb:9:in `<main>'
//}...

Range.new(first, last, exclude_end = false) -> Range (8032.0)

first から last までの範囲オブジェクトを生成して返しま す。

...oday, Date.today >> 1).each {|d| puts d }
# => 2017-09-16
# 2017-09-17
# ...
# 2017-10-16
//}

//emlist[例: IPアドレスの範囲オブジェクトの場合][ruby]{
require 'ipaddr'
Range.new(IPAddr.new("192.0.2.1"), IPAddr.new("192.0.2.3")).each {|ip| puts ip}
# => 192.0.2.1
# 192.0....
...のオブジェクトの場合][ruby]{
MyInteger = Struct.new(:value) do
def succ
self.class.new(value + 1)
end

def <=>(other)
value <=> other.value
end

def to_s
value.to_s
end
end
Range.new(MyInteger.new(1), MyInteger.new(3)).each {|i| puts i }
# => 1
# 2
# 3
//}...

Thread::Backtrace::Location (8026.0)

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

...by]{
# 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.rb:5:in `b'
caller_locations.rb:8:in `c'

//emlist[例2][...
...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
//}

例2の実行結果:

init.rb:4:in `initialize'
init.rb:8:in `new'
init.rb:8:in `<main>'

=== 参考

* Ruby VM アドベン...

絞り込み条件を変える

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

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

...#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
...

Kernel.#print(*arg) -> nil (8014.0)

引数を順に標準出力 $stdout に出力します。引数が与えられない時には変数 $_ の値を出力します。

...えられない時には変数
$_ の値を出力します。

文字列以外のオブジェクトが引数として与えられた場合には、
to_s
メソッドにより文字列に変換してから出力します。

変数 $, (出力フィールドセパレータ)に nil で
ない値がセ...
...た場合に発生します。

//emlist[例][ruby]{
print "Hello, world!"
print "Regexp is",/ant/
print nil
print "\n"
#=> Hello, world!Regexp is(?-mix:ant)

$_ = "input"
$, = "<and>"
$\ = "<end>\n"
print
print "AA","BB"
#=> input<end>
#=> AA<and>BB<end>
//}

@see Kernel.#puts,Kernel.#p,IO#print...

Kernel.#warn(*message) -> nil (8014.0)

message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。

...外のオブジェクトが引数として与えられた場合には、
to_s
メソッドにより文字列に変換してから出力します。

このメソッドは以下と同じです。

//emlist[][ruby]{
$stderr.puts(*message) if !$VERBOSE.nil? && !message.empty?
nil
//}

@param message...

Kernel.#warn(*message, uplevel: nil) -> nil (8014.0)

message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。

...クトが引数として与えられた場合には、
to_s
メソッドにより文字列に変換してから出力します。

uplevel を指定しない場合は、
このメソッドは以下と同じです。

//emlist[][ruby]{
$stderr.puts(*message) if !$VERBOSE.nil? && !message.empty?
nil
/...

Kernel.#warn(*message, uplevel: nil, category: nil) -> nil (8014.0)

message を 標準エラー出力 $stderr に出力します。 $VERBOSE フラグ が nil のときは何も出力しません。

...クトが引数として与えられた場合には、
to_s
メソッドにより文字列に変換してから出力します。

uplevel を指定しない場合は、
このメソッドは以下と同じです。

//emlist[][ruby]{
$stderr.puts(*message) if !$VERBOSE.nil? && !message.empty?
nil
/...

絞り込み条件を変える