How can I DRY this cide?

I have code like this

  def self.find(*args)
    if @@filter
      with_scope :find => {:conditions => @@filter } do
        super
      end
    else
      super
    end
  end

  def self.paginate(*args)
    if @@filter
      with_scope :find => {:conditions => @@filter } do
        super
      end
    else
      super
    end
  end

  def self.related_tag_counts(*args)
    if @@filter
      with_scope :find => {:conditions => @@filter } do
        super
      end
    else
      super
    end
  end

  def self.tag_counts(*args)
    if @@filter
      with_scope :find => {:conditions => @@filter } do
        super
      end
    else
      super
    end
  end

as you can see, I'm wrapping some methods with a with_scope when
@@filtter is set. This is kind of ugly. How can I DRY this code?

Hello,

def self.find(*args)
  find @@filter ? {}.merge(:conditions => @@filter) : {}
  super
end

Something like that is what I would do.

rubynuby wrote:

thanks, but that code causes a stack overflow. I think it's an
infinite recursion. I'm not sure how it works anyway.