Sha256: c1a6cfaf3e004831c3ef8ee9d015c8b044a37e7befaade89704daf60eaab055a
Contents?: true
Size: 1.2 KB
Versions: 16
Compression:
Stored size: 1.2 KB
Contents
class CharacterSet module SetMethodAdapters # Allow some methods to work with String in addition to Integer args # (the internal representation is geared towards codepoint Integers). %w[add add? << delete delete? include? member? ===].each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(arg) case arg when String super(arg.ord) when Integer if arg < 0 || arg > 0x10FFFF raise ArgumentError, 'pass an Integer between 0 and 0x10FFFF' end super(arg) else raise ArgumentError, 'pass a String or an Integer' end end RUBY end # Allow some methods to take an Enum just as well as another CharacterSet. # Tested by ruby-spec. %w[& + - ^ | difference intersection subtract union].each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(arg) if arg.is_a?(CharacterSet) super elsif arg.respond_to?(:each) super(CharacterSet.new(arg.to_a)) else raise ArgumentError, 'pass an enumerable' end end RUBY end end end
Version data entries
16 entries across 16 versions & 1 rubygems