`
zzhang
  • 浏览: 17695 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

define_method with parameters

 
阅读更多

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
 

 

分享到:
评论

相关推荐

    Java_for_the_Web_with_Servlets

    - **`javax.servlet` Package**: This package contains the classes and interfaces that define the Servlet API, including the `Servlet`, `ServletConfig`, and `ServletContext` interfaces. - **Servlet ...

    Using LUA with Visual C++ (Introduction)

    I recommend that you use the first method. The LUA State In order to use LUA you have to initialize it and when you're done with it you have to deinitialize LUA. This is done by respectivily ...

    王小平版遗传算法的光盘源代码

    will run gpcREGRESSION with 2 pops 100 gens with pop0 using the default values, pop1 using values from pop1_file, and 12345 as the initial random seed. On startup default values for the runtime...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFlexControl.Invalidate and can be overriden (it is possible now to catch all object invalidation calls). - FIX: The TFlexPanel....

    最优化学习的Matlab程序:黄金分割法(gold section method)

    % problem-dependent parameters. Suppose you want to solve the equation given % in the function myfun, which is parameterized by its second argument c. Here % myfun is an M-file function such as % % ...

    UG6.0快捷键大全

    MESSAGE Removes all parameters from a solid or sheet body, producing a non-associative body. SYNONYMS orphan, delete, simplify HINT This command is available in history modeling mode. HELP DSN_...

    uCOS-II v2.52 在 STM32 上的移植

    with "#define LCD_RST_H() ( LCD_CTRL_PORT->BSRR = LCD_RST )" for a faster LCD refresh speed. 4.Modify name "LCD_SCI" to "LCD_SI", 'cause it means Serial Interface. 5.Modify function name "LCD_...

    CSharp 3.0 With the .NET Framework 3.5 Unleashed(english)

    - **Overloading Methods**: Method overloading allows you to define multiple methods with the same name but different parameters. - **Overloading Operators**: Operator overloading enables you to define...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    We can declare (but not define) functions with arguments, and/or return values, of type Foo. (One exception is if an argument Foo or const Foo& has a non-explicit, one-argument constructor, in which ...

    programming with objective c

    #### You Can Pass Objects for Method Parameters 方法参数可以传递对象。这意味着可以将一个对象作为参数传递给另一个对象的方法。 #### Methods Can Return Values 方法可以返回值。除了执行操作外,方法还...

    ImageMagick图片批量处理

    -function name parameters apply function over image values -gamma value level of gamma correction -gaussian-blur geometry reduce image noise and reduce detail levels -geometry geometry preferred...

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 2: Consider a builder when faced with many constructor parameters Item 3: Enforce the singleton property with a private constructor or an enum type Item 4: Enforce noninstantiability with a ...

    Objective-C for Absolute Beginners: iPhone and Mac Programming Made Easy

    With over five decades of combined experience in software development, the authors have crafted a highly effective method for teaching Objective-C, drawing on their pioneering work at Carnegie Mellon...

    WPTools.v6.29.1.Pro

    * modified method DeleteColumn * modified WPT reading code to repair table width which were negative + improved image rendering code for transparent (PNG) images. They will be drawn transparently ...

    IOS5 Programming Cookbook

    - **Selector Resolution**: When defining multiple methods with the same name, the selector resolution mechanism determines which method is called based on the arguments passed. ### 14. Allocating and...

    Java邮件开发Fundamentals of the JavaMail API

    With the JavaMail API, in order to communicate with a server, you need a provider for a protocol. The creation of protocol-specific providers is not covered in this course because Sun provides a ...

    acpi控制笔记本风扇转速

    control method attempts to create 2 objects of the same name. This once again returns AE_ALREADY_EXISTS. When this exception occurs, it invokes the mechanism that will dynamically serialize the ...

    VclZip pro v3.10.1

    If you currently work with VCLZip 2.X with TBlobStreams or some other type of streams, you can either define your own TkpBlobStream for instance which inherits from TkpHugeStream, or use the ...

    JSP Simple Examples

    In this example we are making a method named as addNum(int i, int b) which will take two numbers as its parameters and return integer value. Multiple methods Jsp is used mainly for presentation ...

Global site tag (gtag.js) - Google Analytics