るりまサーチ

最速Rubyリファレンスマニュアル検索!
148件ヒット [1-100件を表示] (0.046秒)
トップページ > クエリ:object[x] > クエリ:>[x] > クエリ:Array[x] > クラス:Object[x]

別のキーワード

  1. objectspace each_object
  2. _builtin each_object
  3. object to_enum
  4. object send
  5. object enum_for

ライブラリ

キーワード

検索結果

<< 1 2 > >>

Object#to_ary -> Array (9236.0)

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

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

説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要...
...すべての場面で代置可能であるような、
* 配列そのものとみなせるようなもの
という厳しいものになっています。

//emlist[][ruby]{
class Foo
def to_ary
[3,4]
end
end

it = Foo.new
p([1,2] + it) #=> [1, 2, 3, 4]
//}

@see Object#to_a,Kernel.#Array...

Object#to_a -> Array (9232.0)

オブジェクトを配列に変換した結果を返します。 デフォルトでは定義されていません。

...のメソッドは実際には Object クラスには定義されていません。
必要に応じてサブクラスで定義すべきものです。

//emlist[][ruby]{
p( {'a'=>1}.to_a ) # [["a", 1]]
p ['array'].to_a # ["array"]
p nil.to_a # []
//}

@see Object#to_ary,Kernel.#Array...

Object::ARGV -> Array (9202.0)

Ruby スクリプトに与えられた引数を表す配列です。

Ruby スクリプトに与えられた引数を表す配列です。

組み込み変数 $* の別名です。
Ruby 自身に対する引数は取り除かれています。

例:

スクリプト argv.rb の内容が
p ARGV
であったとします。このときシェルから次を実行すると、
$ ruby argv.rb foo bar baz
結果は以下のように出力されます。
["foo", "bar", "baz"]

Object#pretty_print_cycle(pp) -> () (9129.0)

プリティプリント時にオブジェクトの循環参照が検出された場合、 Object#pretty_print の代わりに呼ばれるメソッドです。

...場合、
Object
#pretty_print の代わりに呼ばれるメソッドです。

あるクラスの pp の出力をカスタマイズしたい場合は、
このメソッドも再定義する必要があります。

@param pp PP オブジェクトです。

//emlist[][ruby]{
class Array
def pretty...
..._print_cycle(q)
q.text(empty? ? '[]' : '[...]')
end
end
//}

@see Object#pretty_print...

Object#class -> Class (9125.0)

レシーバのクラスを返します。

...レシーバのクラスを返します。

//emlist[][ruby]{
p "ruby".class #=> String
p 100.class #=> Integer
p ARGV.class #=> Array
p self.class #=> Object
p Class.class #=> Class
p Kernel.class #=> Module
//}

@see Class#superclass,Object#kind_of?,Object#instance_of?...

絞り込み条件を変える

Object#freeze -> self (9125.0)

オブジェクトを凍結(内容の変更を禁止)します。

...を返します。

//emlist[][ruby]{
a1 = "foo".freeze
a1 = "bar"
p a1 #=> "bar"

a2 = "foo".freeze
a2.replace("bar") # can't modify frozen String (RuntimeError)
//}

凍結を解除することはできませんが、Object#dup を使えばほぼ同じ内容の凍結されていない
オブジ...
...ます。

//emlist[][ruby]{
a = [1].freeze
p a.frozen? #=> true

a[0] = "foo"
p a # can't modify frozen Array (RuntimeError)

b = a.dup
p b #=> [1]
p b.frozen? #=> false

b[0] = "foo"
p b #=> ["foo"]
//}

@see Object#frozen?,Object#dup,Kernel.#trace_var...
...を返します。

//emlist[][ruby]{
a1 = "foo".freeze
a1 = "bar"
p a1 #=> "bar"

a2 = "foo".freeze
a2.replace("bar") # can't modify frozen String (FrozenError)
//}

凍結を解除することはできませんが、Object#dup を使えばほぼ同じ内容の凍結されていない
オブジェ...
...ます。

//emlist[][ruby]{
a = [1].freeze
p a.frozen? #=> true

a[0] = "foo"
p a # can't modify frozen Array (FrozenError)

b = a.dup
p b #=> [1]
p b.frozen? #=> false

b[0] = "foo"
p b #=> ["foo"]
//}

@see Object#frozen?,Object#dup,Kernel.#trace_var...

Object#pretty_print(pp) -> () (9119.0)

PP.pp や Kernel.#pp がオブジェクトの内容を出力するときに 呼ばれるメソッドです。PP オブジェクト pp を引数として呼ばれます。

...P オブジェクトです。

//emlist[][ruby]{
require 'pp'

class Array
def pretty_print(q)
q.group(1, '[', ']') {
q.seplist(self) {|v|
q.pp v
}
}
end
end
//}

@see Object#pretty_print_cycle, Object#inspect, PrettyPrint#text, PrettyPrint#group, PrettyPrint#breakabl...
...@param pp PP オブジェクトです。

//emlist[][ruby]{
class Array
def pretty_print(q)
q.group(1, '[', ']') {
q.seplist(self) {|v|
q.pp v
}
}
end
end
//}

@see Object#pretty_print_cycle, Object#inspect, PrettyPrint#text, PrettyPrint#group, PrettyPrint#breakable...

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

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

...][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 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 (9113.0)

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

...][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 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 > >>