Sha256: 3b8215759943cb8d17feb4c48235d8e56526a80fadc2cb9ea4c423c73f4710bd

Contents?: true

Size: 829 Bytes

Versions: 6

Compression:

Stored size: 829 Bytes

Contents

class Module
  
  def alias_method_chain(target, feature)
    # Strip out punctuation on predicates or bang methods since
    # e.g. target?_without_feature is not a valid method name.
    aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
    yield(aliased_target, punctuation) if block_given?
    alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target
    alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}"
  end
  
  def attr_initialize(*attrs)
    define_method(:initialize) do |*passed|
      raise ArgumentError, "Wrong number of arguments" \
        unless attrs.size == passed.size
  
      attrs.each_with_index do |att, i|
        instance_variable_set("@#{att}", passed[i])
      end
  
      after_initialize if respond_to? :after_initialize
    end
  end

  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
merb-0.2.0 lib/merb/core_ext/merb_module.rb
merb-0.3.1 lib/merb/core_ext/merb_module.rb
merb-0.1.0 lib/merb/core_ext/merb_module.rb
merb-0.3.0 lib/merb/core_ext/merb_module.rb
merb-0.3.3 lib/merb/core_ext/merb_module.rb
merb-0.3.4 lib/merb/core_ext/merb_module.rb