14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/pybind/import.rb', line 14
def pyfrom(mod_name, import: nil)
raise ArgumentError, "missing identifiers to be imported" unless import
mod = PyBind.import(mod_name)
raise PyError.fetch unless mod
case import
when Hash
import.each do |attr, as|
val = mod.get_attribute(attr)
define_singleton_method(as) { val }
end
when Array
import.each do |attr|
val = mod.get_attribute(attr)
define_singleton_method(attr) { val }
end
when Symbol, String
val = mod.get_attribute(import)
define_singleton_method(import) { val }
end
end
|