lib/picky/tokenizer.rb in picky-4.11.3 vs lib/picky/tokenizer.rb in picky-4.12.0
- old
+ new
@@ -97,19 +97,28 @@
#
# Note: We do not test against to_str since symbols do not work with String#split.
#
def splits_text_on thing
raise ArgumentError.new "#{__method__} takes a Regexp or String or a thing that responds to #split as argument, not a #{thing.class}." unless Regexp === thing || thing.respond_to?(:split)
- @splits_text_on = thing
- if thing.respond_to? :split
- def split text
- @splits_text_on.split text
- end
+ @splits_text_on = if thing.respond_to? :split
+ thing
else
- def split text
- text.split @splits_text_on
- end
+ RegexpWrapper.new thing
end
+ end
+ class RegexpWrapper
+ def initialize regexp
+ @regexp = regexp
+ end
+ def split text
+ text.split @regexp
+ end
+ def source
+ @regexp.source
+ end
+ end
+ def split text
+ @splits_text_on.split text
end
# Normalizing.
#
# We only allow arrays.
\ No newline at end of file