拡張モジュールのメソッドの引数チェックですが:

require "mandel"
...

def mandel(x, y)
  re = $s_re + ($dx * x)
  im = $s_im - ($dy * y)
  # z = c = Complex(re, im)
  # for i in 0 .. $max_deapth
  #   z = (z * z) + c
  #   break if z.abs > 2
  # end
  # return i
p re.type
p im.type
p $max_deapth.type
  return Mandel.loop(re, im, $max_deapth)
end


みたいな感じでMandel.loopを呼んでみると、

masao-k@ewb02% !ruby
ruby tkmandel.rb
Float
Float
Fixnum
tkmandel.rb:104:in `loop': wrong argument type Module (expected Float) (TypeError)
        from tkmandel.rb:104:in `mandel'
        from tkmandel.rb:113:in `calc'
        from tkmandel.rb:112:in `each'
        from tkmandel.rb:112:in `calc'
        from tkmandel.rb:153


と、怒られます。なぜ?

ちなみに、mandel.cは以下な感じです:

M.Kanemitsu

−−−
#include "ruby.h"

static VALUE
mandel_loop(re, im, max)
    VALUE re;
    VALUE im;
    VALUE max;
{
    double real, image;
    double z_real, z_image;
    int maximum;
    int i;

    Check_Type(re, T_FLOAT);
    Check_Type(im, T_FLOAT);
    Check_Type(max, T_FIXNUM);

    real = RFLOAT(re)->value;
    image = RFLOAT(im)->value;
    maximum = FIX2INT(max);

    /***
    z = c = Complex(re, im)
    for i in 0 .. $max_deapth
      z = (z * z) + c
      break if z.abs > 2
    end
    return i
    ***/

    z_real = real;
    z_image = image;
    for (i = 0; i < maximum; i++) {
        z_real = ((z_real * z_real) - (z_image * z_image)) + real;
        z_image = ((z_real * z_image) + (z_image * z_real)) + image;
        if ( ((z_real * z_real) + (z_image * z_image)) > 4.0 ) {
            break;
        }
    }
    return INT2FIX(i);
}


Init_mandel()
{
    VALUE mMandel = rb_define_module("Mandel");
    rb_define_singleton_method(mMandel, "loop", mandel_loop, 3);
}
−−−