hoodwink.d enhanced

Wed Mar 22

Quack-attack

Quack attack

Method interception

class Module def intercept_method(method, temporary_result) original_method = "#{Time.now.to_i}_#{method}" alias_method original_method, method # Not enough room for a ternary ;_; t = if temporary_result.respond_to?(:to_proc) temporary_result.to_proc else Proc.new { temporary_result } end define_method(method, t) yield alias_method method, original_method end end class Duck; def quack; 'Quack!' end end Duck.intercept_method(:quack, 'Honk!') do p Duck.new.quack end # => 'Honk!' p Duck.new.quack # => 'Quack!'
‘#fab444’ is the new ‘#ffffcc’

Bruce Williams

The notion of errors is ill-defined.

From the BUGS section of the netstat man page