Sha256: 39bd743e8cb6decc8c380ab24ac48ebc4bd9f6efb97b3c204935b1c63db712c5

Contents?: true

Size: 624 Bytes

Versions: 10

Compression:

Stored size: 624 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

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/module/wrap_method.rb
facets-2.8.3 lib/core/facets/module/wrap_method.rb
facets-2.8.2 lib/core/facets/module/wrap_method.rb
facets-2.8.1 lib/core/facets/module/wrap_method.rb
facets-2.8.0 lib/core/facets/module/wrap_method.rb
facets-2.7.0 lib/core/facets/module/wrap_method.rb
facets-2.6.0 lib/core/facets/module/wrap_method.rb
facets-2.5.1 lib/core/facets/module/wrap_method.rb
facets-2.5.0 lib/core/facets/module/wrap_method.rb
facets-2.5.2 lib/core/facets/module/wrap_method.rb