lib/unf/normalizer_cruby.rb in unf-0.2.0.beta1 vs lib/unf/normalizer_cruby.rb in unf-0.2.0.beta2
- old
+ new
@@ -1,10 +1,9 @@
-begin
- require 'unf_ext'
-rescue LoadError
- String.method_defined?(:unicode_normalize) or raise
-
+case
+when defined?(UNF::Normalizer)
+ # Probably unf_ext is preloaded.
+when String.method_defined?(:unicode_normalize)
class String
[:nfc, :nfd, :nfkc, :nfkd].each { |form|
eval %{
def to_#{form.to_s}
unicode_normalize(#{form.inspect})
@@ -18,6 +17,8 @@
def normalize(string, normalization_form)
String.try_convert(string).unicode_normalize(normalization_form)
end
end
end
+else
+ require 'unf_ext'
end