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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s