Ruby <Ruby 元编程>思维导图 6 (编写代码的代码)

flingjie · May 06, 2014 · 2078 hits

根本没有什么元编程,只有编程!?

  • 注 1: 由于代码字符串和块非常相似,因此,在很多情况下,可以选择使用任意一种。但是,一般情况下,只要能用块就尽量用块。

  • 注 2: 使一个模块可以通过钩子方法扩展它的包含者。

    module M
    def self.included(base)
    base.extend(ClassMethods)
    end
    

module ClassMethods def my_method 'a class method' end end end

class C include M end

C.my_method # => "a class method"

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.