Sha256: 44d9f7144a6def5aa6989b82f8ece0df190b9879415e69122b064dc938d37421

Contents?: true

Size: 626 Bytes

Versions: 4

Compression:

Stored size: 626 Bytes

Contents

class Module

  #private  # (we'll leave this one public for AOP-like uses).

  # Creates a new method wrapping the previous of
  # the same name. Reference to the old method
  # is passed into the new definition block
  # as the first parameter.
  #
  #   wrap_method( sym ) { |old_meth, *args|
  #     old_meth.call
  #     ...
  #   }
  #
  # Keep in mind that this can not be used to wrap methods
  # that take a block.
  #
  #   CREDIT: Trans

  def wrap_method( sym, &blk )
    old = instance_method(sym)
    define_method(sym) { |*args| blk.call(old.bind(self), *args) }
  end

  alias_method :wrap, :wrap_method

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
facets-2.4.3 lib/core/facets/module/wrap_method.rb
facets-2.4.4 lib/core/facets/module/wrap_method.rb
facets-2.4.5 lib/core/facets/module/wrap_method.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/module/wrap_method.rb