Method: Daru.create_has_library

Defined in:
lib/daru.rb

.create_has_library(library) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/daru.rb', line 50

def create_has_library(library)
  lib_underscore = library.to_s.tr('-', '_')
  define_singleton_method("has_#{lib_underscore}?") do
    cv = "@@#{lib_underscore}"
    unless class_variable_defined? cv
      begin
        library = 'nmatrix/nmatrix' if library == :nmatrix
        require library.to_s
        class_variable_set(cv, true)
      rescue LoadError
        # :nocov:
        class_variable_set(cv, false)
        # :nocov:
      end
    end
    class_variable_get(cv)
  end
end