るりまサーチ

最速Rubyリファレンスマニュアル検索!
88件ヒット [1-88件を表示] (0.071秒)
トップページ > クエリ:_builtin[x] > クエリ:new[x] > クエリ:dup[x] > 種類:インスタンスメソッド[x]

別のキーワード

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

ライブラリ

クラス

キーワード

検索結果

Object#initialize_copy(obj) -> object (8049.0)

(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。

...obj の内容で置き換えます。ただ
し、self のインスタンス変数や特異メソッドは変化しません。
Object#clone, Object#dupの内部で使われています。

initialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに使用(定義...
...保持させない場合がありますが、そういった内部情
報を initialize_copy でコピーするよう定義しておくことで、dup や clone
を再定義する必要がなくなります。

デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェ...
...
のクラスと異なる場合に発生します。
@see Object#clone,Object#dup

以下に例として、dup や clone がこのメソッドをどのように利用しているかを示します。

obj.dup は、新たに生成したオブジェクトに対して
initialize_copy を呼び

/...

Hash#replace(other) -> self (8031.0)

ハッシュの内容を other の内容で置き換えます。

...ります。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。

self = other.to_hash.dup と同じです。

@param other ハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return sel...
...{2 => 'B', 3 => 'C'}

foo.replace(bar)
p foo #=> {2=>"B", 3=>"C"}

zoo = {}
zoo = bar.dup
p zoo #=> {2=>"B", 3=>"C"}

class Foo
def to_hash
{:japan => 'kyoto'}
end
end

h = Hash.new
h.replace(Foo.new) #暗黙の変換
p h #=> {:japan=>"kyoto"}
//}

@see Hash#dup,Hash#merge,Object#to_hash...

Array#shuffle -> Array (8013.0)

配列の要素をランダムシャッフルして,その結果を配列として返します。

...ことができます。

//emlist[例][ruby]{
a = [ 1, 2, 3 ] #=> [1, 2, 3]
a.shuffle #=> [2, 3, 1]
rng = Random.new
rng2 = rng.dup # RNGを複製
# 以下の2つは同じ結果を返す
[1,2,3].shuffle(random: rng)
[1,2,3].shuffle(random: rng2)
//}

@see Array#shuffle!...

Array#shuffle(random: Random) -> Array (8013.0)

配列の要素をランダムシャッフルして,その結果を配列として返します。

...ことができます。

//emlist[例][ruby]{
a = [ 1, 2, 3 ] #=> [1, 2, 3]
a.shuffle #=> [2, 3, 1]
rng = Random.new
rng2 = rng.dup # RNGを複製
# 以下の2つは同じ結果を返す
[1,2,3].shuffle(random: rng)
[1,2,3].shuffle(random: rng2)
//}

@see Array#shuffle!...

Encoding::Converter#primitive_convert(source_buffer, destination_buffer) -> Symbol (8013.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...defined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_empty
* :finished

//emlist[][ruby]{
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
src = "abc\x81あいう\u{20bb7}\xe3"
dst = ''

begin
ret = ec.primitive_convert(src, dst)
p [ret, src, dst, ec.primitive_er...
...nvalid_byte_sequence
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_out...

絞り込み条件を変える

Encoding::Converter#primitive_convert(source_buffer, destination_buffer, destination_byteoffset) -> Symbol (8013.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...defined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_empty
* :finished

//emlist[][ruby]{
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
src = "abc\x81あいう\u{20bb7}\xe3"
dst = ''

begin
ret = ec.primitive_convert(src, dst)
p [ret, src, dst, ec.primitive_er...
...nvalid_byte_sequence
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_out...

Encoding::Converter#primitive_convert(source_buffer, destination_buffer, destination_byteoffset, destination_bytesize) -> Symbol (8013.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...defined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_empty
* :finished

//emlist[][ruby]{
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
src = "abc\x81あいう\u{20bb7}\xe3"
dst = ''

begin
ret = ec.primitive_convert(src, dst)
p [ret, src, dst, ec.primitive_er...
...nvalid_byte_sequence
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_out...

Encoding::Converter#primitive_convert(source_buffer, destination_buffer, destination_byteoffset, destination_bytesize, options) -> Symbol (8013.0)

エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。

...defined_conversion
* :after_output
* :destination_buffer_full
* :source_buffer_empty
* :finished

//emlist[][ruby]{
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
src = "abc\x81あいう\u{20bb7}\xe3"
dst = ''

begin
ret = ec.primitive_convert(src, dst)
p [ret, src, dst, ec.primitive_er...
...nvalid_byte_sequence
ec.insert_output(ec.primitive_errinfo[3].dump[1..-2])
redo
when :undefined_conversion
c = ec.primitive_errinfo[3].dup.force_encoding(ec.primitive_errinfo[1])
ec.insert_output('\x{%X:%s}' % [c.ord, c.encoding])
redo
when :incomplete_input
ec.insert_out...