Scripting vim using ruby interface

I know this should be posted to the vim mailing list, but I wasn’t able
to
subscribe to it, so I’m posting here instead.

I’ve been trying to write a vim script using vim’s ruby interface, but I
keep
coming across weird errors in completely unexpected places. A very
simple
example is the following: I give the following command (all in one line,
of
course):

:ruby require ‘pathname’;
Pathname.new(’/home/stefano/Desktop/test_tools/’).realpath

This command, which works perfectly when executed in irb or using ruby
-e or
from a ruby script, when called from vim gives an error:

SystemStackError: /usr/lib/ruby/1.8/pathname.rb:266:in `chop_basename’:
stack
level too deep.

Moreover, these errors seem random: I can run a piece of code once and
it
works; i run it again later and it gives an error like the above one
(it’s
always a SystemStackError). Yet, every time this happens, it’s always in
the
same position.

Does anyone know if there’s a reason for this behaviour, such as some
kind of
restriction to the ruby code you can call in ruby? Has anyone succeeded
in
using ruby interface? I’ve searched google, the vim mailing list and vim
documentation, but I found nothing.

Thanks in advance

Stefano