I was wondering if folks with much more experience with Ruby than I could
comment on my usage of const_missing and method_missing in this code:
class ClrClass
def method_missing(name)
self.class.class_eval do
define_method(name) { name.to_s } # TODO: I will dynamically create IL
shims here @method_count += 1
end
self.method(name).call
end
def get_dotnet_type
self.class.instance_variable_get(:@dotnet_type)
end
def get_method_count
self.class.instance_variable_get(:@method_count)
end
end
class Module
def const_missing(name)
# TODO: I'll lookup the CLR type by prepending names that I find in the
ancestors array - I know that part works already.
c = Class.new(ClrClass)
c.instance_variable_set(:@dotnet_type, name)
c.instance_variable_set(:@method_count, 0)
const_set(name, c)
end
end
The current version of my Ruby <-> CLR bridge doesn't use this technique.
I'd like to use this technique to cache all of my generated CIL shims and
CLR Type objects.
I was wondering if folks with much more experience with Ruby than I could
comment on my usage of const_missing and method_missing in this code:
It's nice, but is there a way to reflect on the .NET target and get at least
the methods all-at-once rather than using method missing? That way you have
the advantage of respond_to? etc. rather than having to refer use a method
first.
It's nice, but is there a way to reflect on the .NET target and get at
least
the methods all-at-once rather than using method missing? That way you
have
the advantage of respond_to? etc. rather than having to refer use a method
first.
I could get the methods all at once, but I use method_missing to determine
which shims I should dynamically construct. Each shim carries some amount of
overhead associated with it in terms of both time and space. I'd like to
avoid constructing shims for methods that are never called.
I wonder if you could override respond_to? and tell it to return 'true' if the method exists virtually.
Duane Johnson
(canadaduane)
ยทยทยท
On Nov 10, 2005, at 3:10 PM, John Lam wrote:
It's nice, but is there a way to reflect on the .NET target and get at
least
the methods all-at-once rather than using method missing? That way you
have
the advantage of respond_to? etc. rather than having to refer use a method
first.
I could get the methods all at once, but I use method_missing to determine
which shims I should dynamically construct. Each shim carries some amount of
overhead associated with it in terms of both time and space. I'd like to
avoid constructing shims for methods that are never called.