Created
October 16, 2013 19:42
-
-
Save alanszp/7013573 to your computer and use it in GitHub Desktop.
Codigo para reemplzar el send... No funciona bien todavia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MethodObserver | |
attr_reader :aspects | |
def self.get_instance | |
@instance == nil ? @instance = new : @instance | |
end | |
private | |
def initialize | |
@aspects = Array.new | |
puts 'Empieza la magia negra' | |
Object.class_eval do | |
alias :old_send :send | |
def send(method,*args) | |
#MethodObserver.get_instance.call_before_method(method, self) | |
puts 'Estoy escribiendo antes' | |
if args.length == 0 | |
self.old_send method | |
else | |
self.old_send method, args | |
end | |
puts 'Estoy escribiendo despues' | |
#MethodObserver.get_instance.call_after_method(method, self) | |
end | |
end | |
end | |
public | |
def add_aspect(aspect) | |
@aspects << aspect | |
end | |
def remove_aspect aspect | |
@aspects.delete(aspect) | |
end | |
def remove_all | |
@aspects.clear | |
end | |
def call_before_method(a_method,a_class) | |
@aspects.each do |aspect| | |
aspect.before_method a_method, a_class | |
end | |
end | |
def call_after_method(a_method,a_class) | |
@aspects.each do |aspect| | |
aspect.after_method a_method, a_class | |
end | |
end | |
def collect_aspects(a_method,a_class) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment