Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/refining.rb
Overview
–
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyleft meh. [http://meh.paranoid.pk | [email protected]]
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
++
Instance Method Summary collapse
Instance Method Details
#refine_singleton_method(meth, options = {}, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/refining.rb', line 14 def refine_singleton_method (meth, = {}, &block) return unless block what = class << self self end if [:alias] || [:prefix] what.instance_eval { begin alias_method [:alias] || "#{[:prefix]}_#{meth}", meth rescue NameError define_method [:alias] || "#{[:prefix]}_#{meth}" do |*args| end end define_method meth, &block } else target = self (method(meth) rescue nil).tap {|old| old ||= proc {} what.instance_eval { define_method meth do |*args, &blk| what.instance_eval { define_method 'temporary method for refining', &block target.__send__('temporary method for refining', old, *args, &blk).tap { undef_method('temporary method for refining') rescue nil } } end } } end end |