るりまサーチ

最速Rubyリファレンスマニュアル検索!
749件ヒット [201-300件を表示] (0.065秒)
トップページ > クエリ:ruby[x] > 種類:インスタンスメソッド[x] > クエリ:>[x] > クエリ:@[x] > クラス:Object[x]

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

キーワード

検索結果

<< < 1 2 3 4 5 ... > >>

Object#display(out = $stdout) -> nil (138.0)

オブジェクトを out に出力します。

...[][ruby]{
class Object
def display(out = $stdout)
out.write self
nil
end
end
//}

@
param out 出力先のIOオブジェクトです。指定しない場合は標準出力に出力されます。
@
return nil を返します。

//emlist[][ruby]{
Object
.new.display #=> #<Object:0xbb0210>
/...

Object#dup -> object (138.0)

オブジェクトの複製を作成して返します。

...bol, そして Numeric クラスのインスタンスなど一部のオブジェクトは複製ではなくインスタンス自身を返します。

@
param freeze true を指定すると freeze されたコピーを返します。
false を指定すると freeze されていないコ...
...す。
@
raise ArgumentError TrueClass などの常に freeze されているオブジェクトの freeze されていないコピーを作成しようとしたときに発生します。

//emlist[][ruby]{
obj = "string"
obj.taint
def obj.fuga
end
obj.freeze

p(obj.equal?(obj)) #=> true
p(o...
...#=> true
p(obj.tainted?) #=> true
p(obj.frozen?) #=> true
p(obj.respond_to?(:fuga)) #=> true

obj_c = obj.clone

p(obj.equal?(obj_c)) #=> false
p(obj == obj_c) #=> true
p(obj_c.tainted?) #=> true
p(obj_c.frozen?) #=> true
p(o...
...#=> true
p(obj.tainted?) #=> false
p(obj.frozen?) #=> true
p(obj.respond_to?(:fuga)) #=> true

obj_c = obj.clone

p(obj.equal?(obj_c)) #=> false
p(obj == obj_c) #=> true
p(obj_c.tainted?) #=> false
p(obj_c.frozen?) #=> true
p(...
...します。
@
raise ArgumentError TrueClass などの常に freeze されているオブジェクトの freeze されていないコピーを作成しようとしたときに発生します。

//emlist[][ruby]{
obj = "string"
def obj.fuga
end
obj.freeze

p(obj.equal?(obj)) #=> true
p(obj =...
...=> true
p(obj.frozen?) #=> true
p(obj.respond_to?(:fuga)) #=> true

obj_c = obj.clone

p(obj.equal?(obj_c)) #=> false
p(obj == obj_c) #=> true
p(obj_c.frozen?) #=> true
p(obj_c.respond_to?(:fuga)) #=> true

obj_d = obj.dup

p(obj.equal?(obj_d)) #=>...

Object#enum_for(method = :each, *args) -> Enumerator (138.0)

Enumerator.new(self, method, *args) を返します。

...ータは引数 args です。


@
param method メソッド名の文字列かシンボルです。
@
param args 呼び出すメソッドに渡される引数です。

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

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :rep...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@
see Enumerator, Enumerator#size...

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (138.0)

Enumerator.new(self, method, *args) を返します。

...ータは引数 args です。


@
param method メソッド名の文字列かシンボルです。
@
param args 呼び出すメソッドに渡される引数です。

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

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :rep...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@
see Enumerator, Enumerator#size...

Object#remove_instance_variable(name) -> object (138.0)

オブジェクトからインスタンス変数 name を取り除き、そのインス タンス変数に設定されていた値を返します。

...を返します。

@
param name 削除するインスタンス変数の名前をシンボルか文字列で指定します。
@
raise NameError オブジェクトがインスタンス変数 name を持たない場合に発生します。

//emlist[][ruby]{
class Foo
def foo
@
foo = 1
p remov...
...e_instance_variable(:@foo) #=> 1
p remove_instance_variable(:@foo) # instance variable @foo not defined (NameError)
end
end
Foo.new.foo
//}

@
see Module#remove_class_variable,Module#remove_const...

絞り込み条件を変える

Object#send(name, *args) -> object (138.0)

オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。

...い場合は
Object
#public_send を使う方が良いでしょう。

@
param name 文字列かSymbol で指定するメソッド名です。
@
param args 呼び出すメソッドに渡す引数です。

//emlist[][ruby]{
p -365.send(:abs) #=> 365
p "ruby".send(:sub,/./,"R") #=> "Ruby"


class Foo...
...注意
methods = {1 => :foo,
2 => :bar,
3 => :baz}

# キーを使って関連するメソッドを呼び出す
# レシーバは任意(Foo クラスのインスタンスである必要もない)
p Foo.new.send(methods[1]) # => "foo"
p Foo.new.send(methods[2]) # => "bar"
p Foo.new.send...
...(methods[3]) # => "baz"
//}

@
see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method...

Object#send(name, *args) { .... } -> object (138.0)

オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。

...い場合は
Object
#public_send を使う方が良いでしょう。

@
param name 文字列かSymbol で指定するメソッド名です。
@
param args 呼び出すメソッドに渡す引数です。

//emlist[][ruby]{
p -365.send(:abs) #=> 365
p "ruby".send(:sub,/./,"R") #=> "Ruby"


class Foo...
...注意
methods = {1 => :foo,
2 => :bar,
3 => :baz}

# キーを使って関連するメソッドを呼び出す
# レシーバは任意(Foo クラスのインスタンスである必要もない)
p Foo.new.send(methods[1]) # => "foo"
p Foo.new.send(methods[2]) # => "bar"
p Foo.new.send...
...(methods[3]) # => "baz"
//}

@
see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method...

Object#to_enum(method = :each, *args) -> Enumerator (138.0)

Enumerator.new(self, method, *args) を返します。

...ータは引数 args です。


@
param method メソッド名の文字列かシンボルです。
@
param args 呼び出すメソッドに渡される引数です。

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

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :rep...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@
see Enumerator, Enumerator#size...

Object#to_enum(method = :each, *args) {|*args| ... } -> Enumerator (138.0)

Enumerator.new(self, method, *args) を返します。

...ータは引数 args です。


@
param method メソッド名の文字列かシンボルです。
@
param args 呼び出すメソッドに渡される引数です。

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

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :rep...
...each do |*val|
n.times { yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@
see Enumerator, Enumerator#size...
<< < 1 2 3 4 5 ... > >>