Sha256: cf9146c4f6716ad40d47b155418d959bcd82282aeddadd7599b72801d7648589

Contents?: true

Size: 1.34 KB

Versions: 11

Compression:

Stored size: 1.34 KB

Contents

# WxRuby Extensions - Dialog functors for wxRuby3
# Copyright (c) M.J.N. Corino, The Netherlands

class Wx::Dialog

  module Functor
    def self.included(klass)
      scope = klass.name.split('::')
      functor_nm = scope.pop
      code = <<~__CODE
        def #{functor_nm}(*args, &block)
          dlg = #{klass.name}.new(*args)
          begin
            if block_given?
              return block.call(dlg)
            else
              return dlg.show_modal
            end
          rescue Exception
            Wx.log_debug "\#{$!}\\n\#{$!.backtrace.join("\\n")}"
            raise
          ensure
            dlg.destroy
          end
        end
        __CODE
      if scope.empty?
        ::Kernel.module_eval code
      else
        scope.inject(::Object) { |mod, nm| mod.const_get(nm) }.singleton_class.module_eval code
      end
      klass.class_eval do
        def self.inherited(sub)
          sub.include Wx::Dialog::Functor
        end
      end
    end
  end

  include Functor

  def self.setup_dialog_functors(mod)
    # find all Dialog descendants in mod and setup the dialog Functor for them
    mod.constants.select do |c|
      ::Class === (const = mod.const_get(c)) && const < Wx::Dialog
    end.each { |c| mod.const_get(c).include Wx::Dialog::Functor }
  end

  setup_dialog_functors(Wx)
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wxruby3-0.9.0.pre.rc.3-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.rc.2-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.rc.1-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.14-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.13-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.11-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.10-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.9-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.8-x64-mingw-ucrt lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.2-x64-mingw-ucrt-3.2-3.2.2 lib/wx/core/dialog.rb
wxruby3-0.9.0.pre.beta.1-x64-mingw-ucrt-3.2 lib/wx/core/dialog.rb