From: John Gabriele Date: 2006-07-11T23:59:14+09:00 Subject: Re: [ANN] ruby-opengl On 7/11/06, Ilmari Heikkinen wrote: > Hi, > > On 7/9/06, Bill Kelly wrote: > > require 'opengl' > > > > class Object > > (GL.methods - Object.methods).each do |m| > > define_method("gl#{m}") {|*args| GL.send(m, *args)} > > end > > > > (GLU.methods - Object.methods).each do |m| > > define_method("glu#{m}") {|*args| GLU.send(m, *args)} > > end > > end > > #define_method makes somewhat slower methods than alias_method. > If an app is making lots of GL calls, it might cause some slowdown. > > I doubt it makes much change in real applications, but here's a silly > micro-benchmark anyhow: > > $ ruby bench_alias_define.rb > user system total real > Foo 0.200000 0.030000 0.230000 ( 0.224021) > FooAlias 0.190000 0.030000 0.220000 ( 0.222571) > FooDelegate 0.810000 0.100000 0.910000 ( 0.909526) I get about the same results on my system too. Nearly the same with bmbm instead of bm too. Thanks for your patience in helping me understand this Ilmari. The ri docs on `extend` don't cover it the way you're using it, and I don't understand the brief explanation in the PickAxe v2 (bottom of p.385). It *looks* to me like putting `extend self` inside a module turns all its instance methods into module methods. All of them -- ones you've already defined, and the ones you're going to define -- *aliases included*. I guess aliases are just like methods in this case (?). Also, it seems that you can use strings in place of Symbols in the args to `alias_method` and `public`. For some reason, that reminds me of a symbolic reference (a la Perl). Anyhow, I see I have more to learn here, and your stategy seems quite a bit faster, so I'll probably go ahead and switch to it unless anyone can point out a reason not to. What do you think Bill? Thanks. Me thinks me need coffee now. ---John