我有以下程序:
class Matcher
include Enumerable
def initialize(string, match)
@string = string
@match = match
end
def each
@string.scan(/[@#match]/) do |pattern|
yield pattern
end
end
end
mch = Matcher.new("the quickbrown fox", "aeiou")
puts mch.inject {|x, n| x+n}
它应该aeiou
与字符串匹配字符the quickbrown fox
无论我把什么作为模式,它都会奇怪地打印出字符:thc
. 这是怎么回事?