Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>class Buyer &lt; ActiveRecord::Base scope :positioned_at_or_above, lambda {|pos| where("position &gt;= ?", pos) } def self.increment(amount, position_threshold) Buyer.positioned_at_or_above(position_threshold).each{|buyer| buyer.update_attributes(:position =&gt; buyer.position + amount)} end end </code></pre> <p>-</p> <pre><code>increment ∴ rails c Loading development environment (Rails 3.0.3) &gt;&gt; Buyer.count =&gt; 0 &gt;&gt; (1..10).each {|idx| Buyer.create(:name =&gt; "Buyer ##{idx}", :position =&gt; idx)} =&gt; 1..10 &gt;&gt; pp Buyer.all [#&lt;Buyer id: 11, name: "Buyer #1", position: 1&gt;, #&lt;Buyer id: 12, name: "Buyer #2", position: 2&gt;, #&lt;Buyer id: 13, name: "Buyer #3", position: 3&gt;, #&lt;Buyer id: 14, name: "Buyer #4", position: 4&gt;, #&lt;Buyer id: 15, name: "Buyer #5", position: 5&gt;, #&lt;Buyer id: 16, name: "Buyer #6", position: 6&gt;, #&lt;Buyer id: 17, name: "Buyer #7", position: 7&gt;, #&lt;Buyer id: 18, name: "Buyer #8", position: 8&gt;, #&lt;Buyer id: 19, name: "Buyer #9", position: 9&gt;, #&lt;Buyer id: 20, name: "Buyer #10", position: 10&gt;] =&gt; nil &gt;&gt; pp Buyer.positioned_at_or_above(4) [#&lt;Buyer id: 14, name: "Buyer #4", position: 4&gt;, #&lt;Buyer id: 15, name: "Buyer #5", position: 5&gt;, #&lt;Buyer id: 16, name: "Buyer #6", position: 6&gt;, #&lt;Buyer id: 17, name: "Buyer #7", position: 7&gt;, #&lt;Buyer id: 18, name: "Buyer #8", position: 8&gt;, #&lt;Buyer id: 19, name: "Buyer #9", position: 9&gt;, #&lt;Buyer id: 20, name: "Buyer #10", position: 10&gt;] =&gt; nil &gt;&gt; pp Buyer.positioned_at_or_above(4).all [#&lt;Buyer id: 14, name: "Buyer #4", position: 4&gt;, #&lt;Buyer id: 15, name: "Buyer #5", position: 5&gt;, #&lt;Buyer id: 16, name: "Buyer #6", position: 6&gt;, #&lt;Buyer id: 17, name: "Buyer #7", position: 7&gt;, #&lt;Buyer id: 18, name: "Buyer #8", position: 8&gt;, #&lt;Buyer id: 19, name: "Buyer #9", position: 9&gt;, #&lt;Buyer id: 20, name: "Buyer #10", position: 10&gt;] =&gt; nil &gt;&gt; Buyer.increment(1000, 4) =&gt; [#&lt;Buyer id: 14, name: "Buyer #4", position: 1004&gt;, #&lt;Buyer id: 15, name: "Buyer #5", position: 1005&gt;, #&lt;Buyer id: 16, name: "Buyer #6", position: 1006&gt;, #&lt;Buyer id: 17, name: "Buyer #7", position: 1007&gt;, #&lt;Buyer id: 18, name: "Buyer #8", position: 1008&gt;, #&lt;Buyer id: 19, name: "Buyer #9", position: 1009&gt;, #&lt;Buyer id: 20, name: "Buyer #10", position: 1010&gt;] &gt;&gt; pp Buyer.all [#&lt;Buyer id: 11, name: "Buyer #1", position: 1&gt;, #&lt;Buyer id: 12, name: "Buyer #2", position: 2&gt;, #&lt;Buyer id: 13, name: "Buyer #3", position: 3&gt;, #&lt;Buyer id: 14, name: "Buyer #4", position: 1004&gt;, #&lt;Buyer id: 15, name: "Buyer #5", position: 1005&gt;, #&lt;Buyer id: 16, name: "Buyer #6", position: 1006&gt;, #&lt;Buyer id: 17, name: "Buyer #7", position: 1007&gt;, #&lt;Buyer id: 18, name: "Buyer #8", position: 1008&gt;, #&lt;Buyer id: 19, name: "Buyer #9", position: 1009&gt;, #&lt;Buyer id: 20, name: "Buyer #10", position: 1010&gt;] =&gt; nil &gt;&gt; </code></pre>
 

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