Ruby 元编程 步骤

Ruby 元编程 方法1.动态方法 (send && fine_method) --动态派发 , 动态创建,动态内省 缩减代码class MyOpn

Ruby 元编程 方法

1.动态方法 (send && fine_method) --  动态派发 , 动态创建,  动态内省 缩减代码

class MyOpneStruct  def initialize    @attributes = {}  end  def method_missing(name,*args)    attribute = name.to_s    if attribute =~ /=$/      @attributes[attribute.chop] = args[0]    else      @attributes[attribute]    end  endendicecream = MyOpneStruct.newicecream.flavor = "vanilla"icecream.flavor