Module: Tapper::ClassMethods

Defined in:
lib/tapper.rb

Instance Method Summary collapse

Instance Method Details

#method_added(name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tapper.rb', line 9

def method_added(name)
  return if private_method_defined?(name) || /_tap/.match(name.to_s) || method_defined?("#{name}_without_tap")

  method = "    def \#{name}_tap\n      tap { \#{name}_without_tap }\n    end\n  EOS\n\n  self.class_eval(method)\n\n  aliased_method = \"alias \#{name}_without_tap \#{name}\"\n  self.class_eval(aliased_method)\n\n  aliased_method = \"alias \#{name} \#{name}_tap\"\n  self.class_eval(aliased_method)\nend\n"