【发布时间】:2018-11-15 16:03:11
【问题描述】:
我需要修补一个类,但希望修补程序对某些模块是本地的。在 Ruby 中我会这样做:
module ArrayExtension
refine Array do
def ===(other)
self.include?(other)
end
end
end
module Foo
using ArrayExtension
def self.foo
case 2
when [1,2] then puts "bingo!"
end
end
end
Foo.foo # => bingo!
puts [1,2] === 2 # => false
Crystal 有类似的东西吗?
【问题讨论】:
-
Crystal 没有办法做到这一点,没有改进。
标签: scope crystal-lang refinements