Module: WindowsGUI::Util::ScopedStruct

Instance Method Summary collapse

Instance Method Details

#new(*args) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/windows_gui/common.rb', line 40

def new(*args)
  raise ArgumentError, 'Cannot accept both arguments and a block' if
    args.length > 0 && block_given?

  struct = super

  return struct unless block_given?

  begin
    yield struct
  ensure
    struct.pointer.free

    p "Native memory for #{struct} freed" if $DEBUG
  end

  nil
end