Sha256: b726469b49f0e8bfd9b0a66dababcf1912e7b618db11e0958e34cf10bf59b2b4
Contents?: true
Size: 1.67 KB
Versions: 3
Compression:
Stored size: 1.67 KB
Contents
class Module # Sets a constant to a value if this has not been previously defined. # def const_set_if_not_defined( const, value ) const_set( const, value ) unless const_defined? const end # Redefines a constant without warning. # def const_reset!( const, value ) send :remove_const, const if const_defined? const const_set( const, value ) end # Defines a set of methods by applying the block on the return value of # another set of methods. Accepts a hash of pairs { mapped_method_symbol => # original_method_symbol } and a block which to chain to the original # method result. # def chain **hash, &block hash.each_pair { |mapped_method_symbol, original_method_symbol| define_method mapped_method_symbol do |*args, &b| block.( send original_method_symbol, *args, &b ) end } end end class Module # Sets a constant to a value if this has not been previously defined. # def const_set_if_not_defined( const, value ) const_set( const, value ) unless const_defined? const end # Redefines a constant without warning. # def const_reset!( const, value ) send :remove_const, const if const_defined? const const_set( const, value ) end # Defines a set of methods by applying the block on the return value of # another set of methods. Accepts a hash of pairs { mapped_method_symbol => # original_method_symbol } and a block which to chain to the original # method result. # def chain **hash, &block hash.each_pair { |mapped_method_symbol, original_method_symbol| define_method mapped_method_symbol do |*args, &b| block.( send original_method_symbol, *args, &b ) end } end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
y_support-2.1.16 | lib/y_support/core_ext/module/misc.rb |
y_support-2.1.13 | lib/y_support/core_ext/module/misc.rb |
y_support-2.1.12 | lib/y_support/core_ext/module/misc.rb |