>> %w(Pending Processing Executed Canceled).each_with_index.map {|v, i| i}
=> [0, 1, 2, 3]

Ruby Get array of indexes from g...

by jibiel, December 08, 2011 00:18, 5 refactorings, tagged with rails, dry, ruby-1.9.2

Using it :in validates_incl...

4b3896c9b63e756621efa3746c32e91b Talk
def sort
    if params[:fact_id]
      @fact = Fact.find_by_id(params[:fact_id]) || Fact.new
...

Ruby Ugly IF, ELSE

by serek.openid.pl, December 18, 2009 10:17, 3 refactorings, tagged with rails, short, dry

Trying to make this a lot c...

597821ce12359ab2d95437c8164d5254 Talk
def show
    
    if params[:course_id] && permitted_to?(:browse, :videos)
...

Ruby Need to DRY this if-else up

by fnjord.myopenid.com, March 25, 2009 17:43, 3 refactorings, tagged with rails, ruby, dry, conditions, if else

I thought of creating a bef...

321bbdb120165eebbaf37e781d4ec71b Talk
class PeopleController < ApplicationController

...

Ruby Re-use code for new and cre...

by Dave, November 05, 2008 09:30, 4 refactorings, tagged with rails, dry, controller

Hello,

I have a 'people'...

997adc3b63a05bf75f833c48fa246e19 Talk
def planned_percent_complete
    if self.planned_complete_in_dollars != nil
      (( self.planned_complete_in_dollars.to_f / self.task.budget.to_f )  * 100).round(2)
...

Ruby Same methods, different Act...

by Chris W., January 08, 2008 18:31, 6 refactorings, tagged with rails, ruby, activerecord, dry

I know there has to be a "r...

D41d8cd98f00b204e9800998ecf8427e Talk