Module: XRC2Ruby::ObjectTypes::InitArgs

Included in:
Window
Defined in:
lib/wx_sugar/xrc/xrc2ruby_types/window.rb

Overview

Module used to manage keyword arguments

Instance Method Summary collapse

Instance Method Details

#inherited(kls) ⇒ Object



32
33
34
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 32

def inherited(kls)
  @init_args.each { | arg, proc | kls.init_arg(arg, &proc) }
end

#init_arg(arg_name, &block) ⇒ Object

Method for defining an element called arg_name which is passed as part of the wxRuby constructor for a class



10
11
12
13
14
15
16
17
18
19
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 10

def init_arg(arg_name, &block)
  attr_writer arg_name
  define_method(arg_name) do
    if val = instance_variable_get("@#{arg_name}")
      block.call(val)
    end
  end
  @init_args ||= {}
  @init_args[arg_name] = block
end

#init_argsObject



4
5
6
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 4

def init_args
  @init_args 
end

#translatable_string_init_arg(arg_name) ⇒ Object

Method for defining a string ctor arg that can be translated using ruby-gettext, if that option is in use. For example - mneu items, button labels.



24
25
26
27
28
29
30
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 24

def translatable_string_init_arg(arg_name)
  if XRC2Ruby.use_gettext
    init_arg(arg_name) { | val | "_(" + val.inspect + ")" }
  else
    init_arg(arg_name) { | val | val.inspect }
  end
end