Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For your first question, the answer is that it makes an array of its parameters.</p> <p>For your second, I have no clue, but it's simple enough.</p> <p>For your third, here it is: In Ruby, defining a global method with the same name as the class is considered good form only when used to construct or convert from object of that type of a more fundamental type. You should not define this method unless you are creating some sort of low type. You could define this for some class like <code>BigInt128</code> but you shouldn't for <code>ObscureOrSpecializedType678</code>. There is also a design for these methods.</p> <p>If the data that you are passed is of the returned type, return it. If the data is of a directly related type, perform obvious conversions (<code>Fixnum</code> to <code>BigInt128</code>). If the data passed in can be converted and is somewhat related (<code>String</code> to <code>Fixnum</code>) convert it (this conversion is usually only for <code>String</code>). If the data can not be converted, throw an exception. You should <strong>NEVER</strong> return a "magic value".</p> <p>The other use of this method is to create a semi-literal syntax for non-literal types. The best examples of this are <code>Rational()</code> and <code>Complex()</code>. These functions, in addition to doing conversions, allow you to create rations and complex numbers in a more natural way (<code>Rational(1, 2)</code> vs. <code>Rational.new(1, 2)</code>). If there is a certain argument list that is simpler to the literal representation of a type, you would define a <code>Classname()</code> method.</p> <p>For the most part, these methods are only part of the core language, and unless you are making a class like <code>BigInt128</code> or <code>FancyString</code> or <code>NaturalNumber</code>, you should not define these methods.</p> <hr> <p>From what I know the defined of these are:</p> <ul> <li><code>Array(*args)</code> -- Returns arguments as an array</li> <li><code>Complex(real, complex)</code> -- Create a complex number with given real and complex parts</li> <li><code>Float(arg)</code> -- Returns <code>arg</code> converted to a float (takes things like strings too)</li> <li><code>Integer(arg)</code> -- Same as <code>Float()</code>, but converts to an integer(floats are truncated)</li> <li><code>Rational(numerator, denominator=1)</code> -- Creates a Rational number with the given parts</li> <li><code>String(arg)</code> -- Converts argument to string by calling <code>to_s</code></li> </ul> <p>Also, some classes define <code>[]</code> as a class method, which is used for more complex initialization from basic data types (usual initialization only, not conversion) such as <code>Hash[]</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload