Tip: Checking if a libguestfs method exists (Ruby)

Use the method respond_to? to check if a method exists before calling it. See also the libguestfs availability API for larger features.

$ irb
irb(main):001:0> require 'guestfs'
=> true
irb(main):002:0> g = Guestfs::create()
=> #<Guestfs::Guestfs:0x7f7b0d88c450>
irb(main):003:0> g.respond_to?( 'set_network' )
=> true
irb(main):004:0> g.respond_to?( 'no_such_method' )
=> false

Leave a comment

Filed under Uncategorized

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.