Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
How to get accepted in Fileice (200% Working) 22/2012
Premium Account
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
Method Hooks in Ruby: any cleaner?
<pre class='prettyprint' language='ruby'># # Project:: Ruby-Snippets # # Author:: Christoph Heindl (mailto:christoph.heindl@gmail.com) # Homepage:: http://cheind.blogspot.com # # == Overview # # Implements <tt>FollowingHook#following</tt>. A # utility to hook into instance methods and execute # custom code after hooked methods are called. # # See discussion at # http://cheind.blogspot.com/2008/12/method-hooks-in-ruby.html # # Contains methods to hook method calls module FollowingHook module ClassMethods private # Hook the provided instance methods so that the block # is executed directly after the specified methods have been invoked. # # There can only be one hook for a single instance method. Further attempts # to hook already hooked methods will be silently ignored. # # +syms+ is list of method symbols or stringified names to hook on # +block+ is the block to execute after hooked method has been invoked. # Block will receive two arguments: the receiver of the method and an argument hash # which contains the invoked method name <tt>:method</tt>, the arguments passed to # the method <tt>:args</tt> and the return value of the method <tt>:return</tt>. # # class Object # include FollowingHook # following :system do |receiver, args| # p "#{args[:method]} called with arguments #{args[:args].join(",")}" # p "return value was #{args[:return]}" # end # end # # system('ruby --version') # # => ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] # # => "system called with arguments ruby --version" # # => "return value was true" # # => true # def following(*syms, &block) syms.each do |sym| # For each symbol str_id = "__#{sym}__hooked__" unless private_instance_methods.include?(str_id) alias_method str_id, sym # Backup original method private str_id # Make backup private define_method sym do |*args| # Replace method ret = __send__ str_id, *args # Invoke backup block.call(self, # Invoke hook :method => sym, :args => args, :return => ret ) ret # Forward return value of method end end end end end # On inclusion, we extend the receiver by the defined class-methods # This is an ruby idiom for defining class methods within a module. def FollowingHook.included(base) base.extend(ClassMethods) end end</pre> <a href="http://www.refactormycode.com/codes/656-method-hooks-in-ruby-any-cleaner" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>