P
Paulo Jabardo
I was playing around with modules when I noticed that
I counld, for example include Math and use sin,cos,etc
as if it were a common method. When I tried to do the
same in irb
module Test
def Test.triple(x)
3*x
end
end
Test.triple 2 =3D> 6
If I include Test from the toplevel
inlcude Test
and then call triple directly I get an error:
irb(main):005:0> triple 2
NoMethodError: undefined method `triple' for
main:Object
from (irb):5
I then tried to implement the same module as an
extension:
#include <ruby.h>
static VALUE triple(VALUE self, VALUE x){
return rb_float_new(3.0*NUM2DBL(x));
}
VALUE modulo;
void Init_TestC(){
modulo =3D rb_define_module("TestC");
rb_define_module_function(modulo, "triple", triple,
1);
}
=20
When I load this extension,
require 'TestC.so'
TestC.triple 2 =3D> 6
include TestC
triple 2 =3D> 6 # No error
I haven't seen this documented. Can I get this same
behaviour from ruby code or do I need to write an
extension?
Thanks
Paulo Jabardo
=09
=09
=09
_______________________________________________________=20
Yahoo! Acesso Gr=E1tis - Internet r=E1pida e gr=E1tis.=20
Instale o discador agora! http://br.acesso.yahoo.com/
I counld, for example include Math and use sin,cos,etc
as if it were a common method. When I tried to do the
same in irb
module Test
def Test.triple(x)
3*x
end
end
Test.triple 2 =3D> 6
If I include Test from the toplevel
inlcude Test
and then call triple directly I get an error:
irb(main):005:0> triple 2
NoMethodError: undefined method `triple' for
main:Object
from (irb):5
I then tried to implement the same module as an
extension:
#include <ruby.h>
static VALUE triple(VALUE self, VALUE x){
return rb_float_new(3.0*NUM2DBL(x));
}
VALUE modulo;
void Init_TestC(){
modulo =3D rb_define_module("TestC");
rb_define_module_function(modulo, "triple", triple,
1);
}
=20
When I load this extension,
require 'TestC.so'
TestC.triple 2 =3D> 6
include TestC
triple 2 =3D> 6 # No error
I haven't seen this documented. Can I get this same
behaviour from ruby code or do I need to write an
extension?
Thanks
Paulo Jabardo
=09
=09
=09
_______________________________________________________=20
Yahoo! Acesso Gr=E1tis - Internet r=E1pida e gr=E1tis.=20
Instale o discador agora! http://br.acesso.yahoo.com/