Module: Wx::KeywordConstructor
- Defined in:
- lib/wx/keyword_ctors.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/wx/keyword_ctors.rb', line 168 def self.included(klass) klass.extend ClassMethods klass.module_eval do alias :pre_wx_kwctor_init :initialize # The new definition of initialize; accepts a parent arg # mixed_args, which may zero or more position args, optionally # terminated with hash keyword args, and an optional block def initialize(parent = :default_ctor, *mixed_args, &block) # allow zero-args ctor for use with XRC if parent == :default_ctor pre_wx_kwctor_init() return end real_args = [ parent ] + self.class.args_as_list(*mixed_args) begin pre_wx_kwctor_init(*real_args) rescue msg = "Error initializing #{self.inspect} \n" + "Sent parameters: #{real_args.inspect}\n" + "Correct parameters are:\n" + self.class.describe_constructor() Kernel.raise ArgumentError, msg end # If a block was given, pass the newly created Window instance # into it; use block if block if block.arity == -1 or block.arity == 0 self.instance_eval(&block) elsif block.arity == 1 block.call(self) else Kernel.raise ArgumentError, "Block to initialize accepts zero or one arg" end end end end # Any class inheriting from a class including this module must have # its own copy of the param_spec def klass.inherited(sub_klass) sub_klass.instance_variable_set(:@param_spec, instance_variable_get(:@param_spec) ) end end |