Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not quite sure what <code>js_funct</code> should do. <code>res</code> in it is completely useless:</p> <pre><code>def js_funct if @flipped_on res = my_funct if res return res.length end end return nil end </code></pre> <p>You could just say <code>my_funct.length</code> and get the length of whatever the function <code>my_funct</code> returns.</p> <p>But it seems that following thing confuses you: in Ruby, functions (we call them methods, as they always belong to an object) are not first-class objects. So you can't say <code>res = my_funct</code>, hoping that you would assign a <em>function</em> to a variable, as you would in JavaScript. In Ruby, that line would first <em>execute</em> <code>my_funct</code> method, and put its <em>result</em> into variable named <code>res</code>.</p> <p>If you would like to check if a method is defined, you can, for example, use <a href="http://www.ruby-doc.org/core/classes/Object.html#M001005" rel="nofollow"><code>Object#respond_to?</code></a> method.</p> <p>If you would like to wrap your method into an object in order to pass it around, you should use <a href="http://www.ruby-doc.org/core/classes/Object.html#M001038" rel="nofollow"><code>Object#method</code></a> method. But in Ruby it's more common to pass <em>blocks</em> (closures) around, rather than whole <em>methods</em>. You are in fact doing that every time you use <code>map</code>, <code>each</code> or other common Ruby methods.</p> <p>If you would want to see how a particular task is coded in Ruby, you should say what the task is. Your example doesn't tell that.</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. 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