Hi,
I created a proxy class like this one:
class SavingProxy
attr_reader :context
delegate :class, :to => :context
delegate :is_a?, :to => :context
delegate :inspect, :to => :context
delegate :type, :to => :context
def initialize(context)
@context = context
@messages = []
end
def send_if_possible(sym, *args)
new_context = @context.send(sym, *args) if @context.respond_to? sym
@context = new_context if @context.class == new_context.class
new_context
end
private
def method_missing(method, *args, &block)
puts "Sending method #{method} to #{@context.name rescue nil}"
new_context = @context.send(method, *args, &block)
@context = new_context if @context.class == new_context.class
new_context
ensure
@messages << [method, args, block, Time.now - start]
end
end
Now my problem is that I would like this proxyclass to behave exactly like the object it proxies
So for example if I did
[4,5,[1,3], SavingProxy.new([2,3])].flatten
I would like to get this:
[4,5,1,3,2,3]
How could i do that?
I looked a bit and found that in the code for flatten my proxy is not recognized as a n array by rb_check_array_type.
Is it possible to make rb_check_array_type recognize my proxy as an array when my proxy proxies an array?
Thanks
···
---------------------------------
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail