Sha256: 03add25dab37f35e7d21436d80a3ec22eb206b3b0da4abc90895098660133af3
Contents?: true
Size: 1.26 KB
Versions: 36
Compression:
Stored size: 1.26 KB
Contents
# Module overloads class Module # Gives us alias_method_chain from rails def alias_method_chain(target, feature) aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 yield(aliased_target, punctuation) if block_given? with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}" alias_method without_method, target alias_method target, with_method case when public_method_defined?(without_method) public target when protected_method_defined?(without_method) protected target when private_method_defined?(without_method) private target end end def attr_accessor_with_default( *syms, &block ) raise 'Default value in block required' unless block syms.each do | sym | module_eval do attr_writer( sym ) define_method( sym ) do | | class << self; self; end.class_eval do attr_reader( sym ) end instance_variables.include?("@#{sym}") ? instance_variable_get( "@#{sym}" ) : instance_variable_set( "@#{sym}", block.call ) end end end nil end def instance_variables_from_hash(h={}) h.each {|k,v| instance_eval "@#{k} = #{v}"} end end
Version data entries
36 entries across 36 versions & 3 rubygems