Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might want to take a look at this:</p> <p><a href="http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html" rel="nofollow">http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html</a></p> <p>You can include a module in a class, and thereby make that module's methods available to that class.</p> <p>If you include Enumerable into a Rails model, then its methods would be available to that model. But since Enumerable's methods are already available to certain types of objects inside your Rails project, and those objects are available to be instantiated from inside your model, I don't see why you might do that, because Enumerable's methods are working just fine for the purposes they were designed.</p> <p>Anyway, you might find that one of the following might work for you:</p> <p>-- use Activerecord's sum method</p> <p>-- convert your object to an array, and use Enumerable's sum method</p> <p>-- write your own method, but don't call it sum, because you don't want to confuse yourself.</p> <p>Try commenting out the second occurrence of module Neuone in the following snippet, and see what happens. Then try commenting out the Charlie.one method, and see what happens.</p> <pre><code>module Neuone def one 'neuone one' end def two 'neuone two' end </code></pre> <p>end</p> <pre><code>module Neuone def two 'neuone two two' end </code></pre> <p>end</p> <p>class Charlie include Neuone</p> <pre><code>def one 'charlie one' end </code></pre> <p>end</p> <p>c = Charlie.new p c.one p c.two</p>
    singulars
    1. This table or related slice is empty.
    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