るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 > >>

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

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

...[例: 整数の範囲オブジェクトの場合][ruby]{
Range.new(1, 10) # => 1..10
Range.new(1, 10, true) # => 1...10
//}

//emlist[例: 日付オブジェクトの範囲オブジェクトの場合][ruby]{
require 'date'
Range.new(Date.today, Date.today >> 1).each {|d| puts d }
# => 2017-09-...
...y]{
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.2.2
# 192.0.2.3
//}

//emlist[例: 自作のオブジェクトの場合][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#to_s -> String (26119.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>'
//}...

Object#to_s -> String (26113.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...

Module#to_s -> String (23137.0)

モジュールやクラスの名前を文字列で返します。

...lass C
end
end

p A.name #=> "A"
p A::B.name #=> "A::B"
p A::C.name #=> "A::C"

# 名前のないモジュール / クラス
p Module.new.name #=> nil
p Class.new.name #=> nil
p Module.new.to_s #=> "#<Module:0x00007f90b09112c8>"
p Class.new.to_s #=> "#<Class:0x00007fa5c40b41b0>"
//}...

Struct#to_s -> String (23119.0)

self の内容を人間に読みやすい文字列にして返します。

...スに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.inspect # => "#<s...

絞り込み条件を変える

Method#to_s -> String (23113.0)

self を読みやすい文字列として返します。

...

//emlist[例][ruby]{
module Foo
def foo
"foo"
end
end
class Bar
include Foo
def bar
end
end

p Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo>
p Bar.new.method(:bar) # => #<Method: Bar#bar>
//}

klass1 と klass2 が同じ場合は以下の形式になります。...
...st[例][ruby]{
module Foo
def foo
"foo"
end
end
class Bar
include Foo
def bar(a, b)
end
end

p Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo() test.rb:2>
p Bar.new.method(:bar) # => #<Method: Bar#bar(a, b) test.rb:8>
//}

klass1 と klass2 が同じ場合は以下の...

Proc#to_s -> String (23113.0)

self の文字列表現を返します。

...self の文字列表現を返します。

可能なら self を生成したソースファイル名、行番号を含みます。

//emlist[例][ruby]{
p Proc.new {
true
}.to_s

# => "#<Proc:0x0x401a880c@-:3>"
//}...

Data#to_s -> String (23107.0)

self の内容を人間に読みやすい文字列にして返します。

...容を人間に読みやすい文字列にして返します。

//emlist[例][ruby]{
Customer = Data.define(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.inspect # => "#<data Customer name=\"Joe Smith\", address=\"123 Maple, Anytown NC\", zip=12345>"
//}...

Thread#to_s -> String (23107.0)

自身を人間が読める形式に変換した文字列を返します。

...自身を人間が読める形式に変換した文字列を返します。

//emlist[例][ruby]{
a = Thread.current
a.inspect # => "#<Thread:0x00007fdbaf07ddb0 run>"
b = Thread.new{}
b.inspect # => "#<Thread:0x00007fdbaf8f7d10@(irb):3 dead>"
//}...

Object#to_str -> String (14112.0)

オブジェクトの String への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。

...面で代置可能であるような、
* 文字列そのものとみなせるようなもの
という厳しいものになっています。

//emlist[][ruby]{
class Foo
def to_str
'Edition'
end
end

it = Foo.new
p('Second' + it) #=> "SecondEdition"
//}

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

絞り込み条件を変える

Module#inspect -> String (8037.0)

モジュールやクラスの名前を文字列で返します。

...lass C
end
end

p A.name #=> "A"
p A::B.name #=> "A::B"
p A::C.name #=> "A::C"

# 名前のないモジュール / クラス
p Module.new.name #=> nil
p Class.new.name #=> nil
p Module.new.to_s #=> "#<Module:0x00007f90b09112c8>"
p Class.new.to_s #=> "#<Class:0x00007fa5c40b41b0>"
//}...
<< 1 2 3 > >>