In rails how can I delegate to a class method

后端 未结 3 694
半阙折子戏
半阙折子戏 2020-12-29 21:25
class Task < ActiveRecord::Base
  attr_accessible :due_date, :text

  def self.this_week
    where(:due_date => Date.tod         


        
3条回答
  •  清酒与你
    2020-12-29 21:47

    Delegate a method to a class method, considering inheritance:

    delegate :this_week, :to => :class
    

    You can delegate to a specific class like so (see also Isaac Betesh's answer):

    delegate :this_week, :to => :Task
    

    Docs are available here: http://api.rubyonrails.org/classes/Module.html#method-i-delegate

提交回复
热议问题