J
John Lam
------=_Part_45823_27972356.1131568324949
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
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 +=3D 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 =3D 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.
Thanks
-John
http://www.iunknown.com
PS Here are the tests that I used:
class MethodMissingTests < Test::Unit::TestCase
def setup
@obj =3D System.new
end
def test_const_missing
assert_equal :System, @obj.get_dotnet_type
end
def test_method_missing
assert_equal "joe", @obj.joe
assert_equal 1, @obj.get_method_count
end
def test_method_proxy_caching
assert_equal "joe", @obj.joe
assert_equal "bob", @obj.bob
assert_equal 2, @obj.get_method_count
assert_equal "joe", @obj.joe
assert_equal 2, @obj.get_method_count
assert_equal "kim", @obj.kim
assert_equal 3, @obj.get_method_count
end
end
------=_Part_45823_27972356.1131568324949--
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
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 +=3D 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 =3D 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.
Thanks
-John
http://www.iunknown.com
PS Here are the tests that I used:
class MethodMissingTests < Test::Unit::TestCase
def setup
@obj =3D System.new
end
def test_const_missing
assert_equal :System, @obj.get_dotnet_type
end
def test_method_missing
assert_equal "joe", @obj.joe
assert_equal 1, @obj.get_method_count
end
def test_method_proxy_caching
assert_equal "joe", @obj.joe
assert_equal "bob", @obj.bob
assert_equal 2, @obj.get_method_count
assert_equal "joe", @obj.joe
assert_equal 2, @obj.get_method_count
assert_equal "kim", @obj.kim
assert_equal 3, @obj.get_method_count
end
end
------=_Part_45823_27972356.1131568324949--