Sha256: 02aa6d1cec6e9e5c14dd402ba5a7b262bd1a62ae6fb7de9b64075b3b4483d9a7
Contents?: true
Size: 621 Bytes
Versions: 3
Compression:
Stored size: 621 Bytes
Contents
class Module # Creates a new method wrapping the previous of # the same name, passing it into the block # definition of the new method. # # This can not be used to wrap methods that take # a block. # # require 'facet/module/wrap_method' # # wrap_method( sym ) { |old_meth, *args| # old_meth.call # ... # } # def wrap_method( sym, &blk ) raise ArgumentError, "method does not exist" unless method_defined?( sym ) old = instance_method(sym) undef_method(sym); define_method(sym) { |*args| blk.call(old.bind(self), *args) } end private :wrap_method end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
facets-0.7.0 | lib/facet/module/wrap_method.rb |
facets-0.7.1 | lib/facet/module/wrap_method.rb |
facets-0.7.2 | lib/facet/module/wrap_method.rb |