diff --git a/lib/levenshtein.rb b/lib/levenshtein.rb index f2f120d..4e48acc 100644 --- a/lib/levenshtein.rb +++ b/lib/levenshtein.rb @@ -4,10 +4,10 @@ module Levenshtein class << self extend FFI::Library - # Try loading in order. - library = File.dirname(__FILE__) + "/../ext/levenshtein/levenshtein" - candidates = ['.bundle', '.so', '.dylib', ''].map { |ext| library + ext } - ffi_lib(candidates) + library = "levenshtein.#{RbConfig::MAKEFILE_CONFIG['DLEXT']}" + candidates = ["#{__FILE__}/..", "#{__FILE__}/../../ext/levenshtein"] + candidates.unshift(Gem.loaded_specs['levenshtein-ffi'].extension_dir) if Gem.loaded_specs['levenshtein-ffi'] + ffi_lib(candidates.map { |dir| File.expand_path(library, dir) }) # Safe version of distance, checks that arguments are really strings. def distance(str1, str2)