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

lanzhiheng · August 27, 2017 · Last by lanzhiheng replied at September 01, 2017 · 2966 hits
lanzhiheng in Ruby 动态删除方法中的打印语句 mention this topic. 27 Aug 15:37

嘿嘿,元编程里的

Reply to laplace

哈哈 是的

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

Reply to gyorou

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

Reply to 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>'
Reply to 5swords

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

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