define_method with parameters

698 단어 parameter
refactor below code:
 
  def preparation?(page_group)
    page_group.class_name == "preparation".camelize
  end
 
  def task_card?(page_group)
    page_group.class_name == "task_card".camelize
  end
 
  def extra_content?(page_group)
    page_group.class_name == "extra_content".camelize
  end
 
use define_method: 
  ["preparation", "task_card", "extra_content"].each do |t|
    define_method "#{t}?" do |page_group|
      page_group.class_name == t.camelize
    end
  end
 

좋은 웹페이지 즐겨찾기