Ruby 写了篇文章来细说 Ruby 的细化功能

lanzhiheng · 2017年08月27日 · 最后由 lanzhiheng 回复于 2017年09月01日 · 2966 次阅读
lanzhiheng Ruby 动态删除方法中的打印语句 提及了此话题。 08月27日 15:37

嘿嘿,元编程里的

laplace 回复

哈哈 是的

赞。 吐个槽,文中只有局限性 (limitation),没有介绍到坏处 (cons)

gyorou 回复

暂时还没深入了解坏处。😅

lanzhiheng 回复

哈哈我是吐槽标题,不是 pros 和 cons 嘛。 开个小玩笑。

def method_with_print
  using A
  p "begin method"
  puts "This is '#{self.method(:method_with_print).name}' method"
  p "end method"
end
test.rb:2:in `using': main.using is permitted only at toplevel (RuntimeError)
    from test.rb:2:in `method_with_print'
    from test.rb:17:in `<main>'
5swords 回复

Ruby 版本是?我记得新版本的 Ruby 是不支持在顶层作用域使用细化。如果要using得用 module来包裹了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号