Where is the documentation for Array () located?

Looking through the ruleby source code, I noticed that they called Container (: and) , which I rarely see. In fact, the only other place I've seen is in the gem of manufacture

A quick look showed that Container subclasses Array , and a quick jump in Pryshowed that Array(:anything) #=> [:anything].

Another quick look at the ruby ​​documentation for Array does not shed light on this question.

Which method is called Array(), where is it documented, how to define a method like this, and is it considered "bad" in ruby?

+3
source share
3

, .

, , .

: Ruby , , . , - . , BigInt128, ObscureOrSpecializedType678. .

, . , (Fixnum to BigInt128). (String to Fixnum), ( String). , . " ".

. Rational() Complex(). , , (Rational(1, 2) vs. Rational.new(1, 2)). , , Classname().

, BigInt128 FancyString NaturalNumber, .


, , :

  • Array(*args) -
  • Complex(real, complex) - .
  • Float(arg) - arg, float ( )
  • Integer(arg) - , Float(), ( )
  • Rational(numerator, denominator=1) - Rational-
  • String(arg) - , to_s

, [] , ( , ), Hash[].

+2

, , iurb, , .

,

class MyClass
  def initialize(arg)
    puts "Initialized with #{arg.to_s}"
  end
end

def MyClass(arg)
  MyClass.new(arg)
end

irb(main):009:0> MyClass(1)
Initialized with 1
=> #<MyClass:0x4770e10>
+2

uhhhh, Pry, Pry ?!?!

[25] (pry) main: 0> show-doc Array

From: object.c in Ruby Core (C Method):
Number of lines: 4
Owner: Kernel
Visibility: private
Signature: Array(arg1)

Returns arg as an Array. First tries to call
arg.to_ary, then arg.to_a.

   Array(1..5)   #=> [1, 2, 3, 4, 5]
[26] (pry) main: 0> show-method Array

From: object.c in Ruby Core (C Method):
Number of lines: 5
Owner: Kernel
Visibility: private

static VALUE
rb_f_array(VALUE obj, VALUE arg)
{
    return rb_Array(arg);
}
[27] (pry) main: 0> 
+1

All Articles