I have a share object lib that I attach functions from, using ruby ffi. I want to attach each function with an alias and make the alias' private, because calling them can be dangerous. I am wrapping each function in their own ruby module function, here is a quick example:
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :free, [:pointer], :void
end
module MyModule
class << self
extend FFI::Library
ffi_lib '../my_shared_lib.so'
def function(str)
is_string(str)
ptr = ffi_function(str)
result = String.new(ptr.read_string)
LibC.free(ptr)
result
end
private
# attach function
attach_function :ffi_function, :function, [:string], :pointer
def is_string(object)
unless object.kind_of? String
raise TypeError,
"Wrong argument type #{object.class} (expected String)"
end
end
end
end
The function ffi_function
appears to still be callable outside of the module. How can I make it completely private?