Sha256: abdd1184c5a54c739245e508e0106e2d78f9bb8d3f126921ded6950131ad7728
Contents?: true
Size: 972 Bytes
Versions: 2
Compression:
Stored size: 972 Bytes
Contents
module SwingSupport module Extensions # Module allows including classes to process blocks given to constructor # If the class defines #add_block_listener method, block is treated as default listener, # otherwise, newly constructed object is just yielded to the block module Blocks def self.included host host.send :extend, ClassMethods host.instance_eval do alias :new_without_blocks :new alias :new :new_with_blocks end end module ClassMethods def new_with_blocks(*args, &block) component = self.new_without_blocks(*args) if block_given? if component.respond_to? :add_block_listener component.add_block_listener &block else # TODO: some kind of fancy processing of nested blocks/components yield component end end component end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
swing-0.1.16 | lib/swing_support/extensions/blocks.rb |
swing-0.1.15 | lib/swing_support/extensions/blocks.rb |