Module: CharacterSet::RubyFallback::CharacterSetMethods::ClassMethods

Defined in:
lib/character_set/ruby_fallback/character_set_methods.rb

Instance Method Summary collapse

Instance Method Details

#from_ranges(*ranges) ⇒ Object



5
6
7
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 5

def from_ranges(*ranges)
  new(Array(ranges).flat_map(&:to_a))
end

#of_string(str) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/character_set/ruby_fallback/character_set_methods.rb', line 9

def of_string(str)
  raise ArgumentError, 'pass a String' unless str.respond_to?(:codepoints)
  str.encode('utf-8').each_codepoint.with_object(new) { |cp, set| set << cp }
end