NAME

Ruby - Perl interface to Ruby interpreter

SYNOPSIS

use Ruby
	':DEFAULT',

	-require  => 'complex',     # load Ruby's library
		     'digest/md5',  # load Ruby's extention

	-function => 'Rational',    # import Ruby's function

	-class    => qw(GC Object), # import Ruby's classes
	-module   => qw(Kernel),    # synonym for -class

	-variable => ['$!' => '$rb_errinfo'],    # $! as $rb_errinfo
	-function => ['String' => 's'],          # String() as &s()
	-class    => ['Config' => 'RubyConfig'], # Config as RubyConfig

	-literal  => 'all',   # literals are overloaded
	-no_literal => 'all',

	-autobox,             # literals are autoboxed
	-no_autobox,

	-eval => <<'EOR', # eval and import 'add()', 'MyObject'
		def add(x,y)
			x.to_f + x.to_f
		end

		class MyObject
			def my_method
				"OK"
			end
		end
EOR
;
use Ruby -all; # -function => ':DEFAULT' && -class => ':ALL' && -literal

p($Ruby::Version); # => "1.8.6", for example

p(add(1, 2));           # => 3.0
p(MyObject->my_method); # => "OK"

rb_eval(<<'EOS', __PACKAGE__);

	p __PACKAGE__; # => "main"

	Perl::eval("use LWP::Simple");

	# should be Perl's string
	uri = Perl.String("http://www.ruby-lang.org/");
	getprint(uri); # call # &main::getprint
EOS

use Ruby -literal;
# String/Integer/Float are overloaded

p "foo"->class; # String

p ref("foo"); # "Ruby::Object"

10->times(sub{ p @_ });

p "foo"->upcase;

use Ruby -autobox;

[qw(foo bar baz)]->each(sub{ p @_ });

DESCRIPTION

This module provides an interface to a ruby interpreter that is installed in your machine.

IMPORT COMMAND

-function => functions =item -variable => global_variables

Imports functions and/or global_variables.

-variable is a synonym for -funcion.

-class => classes =item -module => modules

Installs classes and/or modules of Ruby.

-module is a synonym for class.

-all

Does -function => ':DEFAULT', -class => ':ALL', -literal.

-require => libraries

Loads libraries at the compile time.

-eval => source_code

Evals source_code, and imports the classes and functions that are defined in source_code.

-base => base_class

Sets up the is-a relationship with base_class, like base.pm.

-literal => [ 'all' | 'string' | 'numeric' | 'integer' | 'float' ] =item -no_literal

Enables/Disables literal overloading.

-autobox =item -no_autobox

Enables/Disables literal autoboxing.

INTERPRETER FEATURE

Constants

These are imported by default.

true
false
nil

Functions

These are imported by default.

rb_eval(source [, package [, file [, line]]])

Evals source as Ruby code.

If package is supplied, those classes and functions that are defined in source are exported to package automatically.

rb_require(library)

Loads library at the run time.

p(...), puts(...)

Equivalent to ruby's p() and puts().

rubyify(perldata)

Rubyifies perldata to use some ruby-like methods.

For example:

rubyify(\%ENV)->each(sub{
	my($key, $value) = @_;
	puts "$key=$value";
});

This method doesn't convert perldata to Ruby data. It wraps perldata with Ruby object.

These functions are importable:

rb_c(class)
rb_m(module)
rb_e(exception)

Obtains the defined class, module or exception object.

rb_const(constant)

Obtains the constant.

For example:

p rb_const(RUBY_VERSION);
p rb_const(File::Constant);# == rb_c(File::Constant)

RUBY FUNCTIONS

Those functions defined in Ruby interpreter are importable.

For example:

use Ruby qw(lambda(&));

my $lambda = lambda { ... };
$lambda->(...);

NOTE

Continuation, catch/throw

Ruby's callcc and catch/throw functions throw LocalJumpError.

Ruby thread

Ruby threads may cause core dumps.

Perl thread

Perl threads will cause core dumps.

BUGS

This module is very experimental. There are a lot of bugs.

SEE ALSO

http://www.ruby-lang.org/.

AUTHOR

Goro Fuji (藤 吾郎) <gfuji(at)cpan.org>

LICENSE AND COPYRIGHT

Copyright (c) 2008, Goro Fuji. Some rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.