add condition

813 단어 Condition
먼저 방법을 하나 써라.
 
class Array
  def add_condition(condition, conjunction = 'and')
    if condition.is_a? Array
      if self.empty?
        (self << condition).flatten!
      else
        self[0] += " #{conjunction} " + condition.shift
        (self << condition).flatten!
      end
    elsif condition.is_a? String
      self[0] += " #{conjunction} " + condition
    else
      raise "don't know how to handle this condition type"
    end
    self
  end
end

 
구체적인 예:
 
conditions = ['active = ? and type = ?', true, 2]
conditions.add_condition ['person_id = ?', 345]

좋은 웹페이지 즐겨찾기