fiddle icon indicating copy to clipboard operation
fiddle copied to clipboard

Add `sym_defined?` methods to test if a symbol is defined

Open tenderlove opened this issue 3 years ago • 0 comments

I would like to check if a symbol is defined before trying to access it. Some symbols aren't available on all platforms, so instead of raising an exception, I want to check if it's defined first.

Today we have to do:

begin
  addr = Fiddle::Handle.sym("something")
  # do something
rescue Fiddle::DLError
end

I want to write this:

if Fiddle::Handle.sym_defined?("something")
  addr = Fiddle::Handle.sym("something")
  # do something
end

tenderlove avatar May 04 '22 16:05 tenderlove