Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not a Ruby specific problem, it's the same for all dynamically typed languages.</p> <p>Usually there are no guidelines for how to document this either (and most of the time not really possible). See for instance <a href="http://ruby-doc.org/core-2.0.0/Array.html#method-i-map" rel="nofollow">map</a> in the ruby documentation</p> <pre><code>map { |item| block } → new_ary map → Enumerator </code></pre> <p>What is <code>item</code>, <code>block</code> and <code>new_ary</code> here and how are they related? There's no way to tell unless you know the implementation or can infer it from the name of the function somehow. Specifying the type is also hard since <code>new_ary</code> depends on what <code>block</code> returns, which in turn depends on the type of <code>item</code>, which could be different for each element in the Array.</p> <p>A lot of times you also stumble across documentation that says that an argument is of type <code>Object</code>, Which again tells you nothing since everything is an Object.</p> <p>OCaml has a solution for this, it supports structural typing so a function that needs an object with a property <code>foo</code> that's a <code>String</code> will be inferred to be <code>{ foo : String }</code> instead of a concrete type. But OCaml is still statically typed.</p> <p>Worth noting is that this can be a problem in statically typed lanugages too. Scala has very generic methods on collections which leads to type signatures like <code>++[B &gt;: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Array[T], B, That]): That</code> for appending two collections.</p> <p>So most of the time, you will just have to learn this by heart in dynamically typed languages, and perhaps help improve the documentation of libraries you are using.</p> <p>And this is why I prefer static typing ;)</p> <p><strong>Edit</strong> One thing that might make sense is to do what Scala also does. It doesn't actually show you that type signature for <code>++</code> by default, instead it shows <code>++[B](that: GenTraversableOnce[B]): Array[B]</code> which is not as generic, but probably covers most of the use cases. So for Ruby's map it could have a monomorphic type signature like <code>Array&lt;a&gt; -&gt; (a -&gt; b) -&gt; Array&lt;b&gt;</code>. It's only correct for the cases where the list only contains values of one type and the block only returns elements of one other type, but it's much easier to understand and gives a good overview of what the function does.</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. 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