export v0.1.0 Export.Ruby

Wrapper for ruby.

Example

defmodule SomeRubyCall do
  use Export.Ruby

  def call_ruby_method
    # path to ruby files
    {:ok, ruby} = Ruby.start(ruby_lib: Path.expand("lib/ruby"))

    # call "upcase" method from "test" file with "hello" argument
    ruby |> Ruby.call("test", "upcase", ["hello"])

    # same as above but prettier
    ruby |> Ruby.call(upcase("hello"), from_file: "test")
  end
end

Summary

Functions

Start Ruby instance with the default options

Start Ruby instance with options. The options argument should be a map with the following options

Start Ruby instance with name and options. The instance will be registered with name. The options argument should be a map with the following options

The same as start/0 except the link to the current process is also created

The same as start/1 except the link to the current process is also created

The same as start/2 except the link to the current process is also created

Stop Ruby instance

Functions

call(instance, file, function, arguments)

Call Ruby function.

Parameters

  • instance: pid witch is returned by one of the start function
  • file: file to run ruby function from
  • function: name of the function
  • arguments: arguments to pass to the function

Example

# call "upcase" method from "test" file with "hello" argument
ruby |> Ruby.call("test", "upcase", ["hello"])
start()

Start Ruby instance with the default options.

Returns {:ok, pid}.

Examples

iex> Export.Ruby.start()
{:ok, pid}
start(options)

Start Ruby instance with options. The options argument should be a map with the following options.

Ruby options

  • ruby: Path to the Ruby interpreter executable
  • ruby_lib: The Ruby programs search path. The Path variable can be a string in RUBYLIB format or a list of paths.
start(name, options)

Start Ruby instance with name and options. The instance will be registered with name. The options argument should be a map with the following options.

Ruby options

  • ruby: Path to the Ruby interpreter executable
  • ruby_lib: The Ruby programs search path. The Path variable can be a string in RUBYLIB format or a list of paths.
start_link()

The same as start/0 except the link to the current process is also created.

start_link(options)

The same as start/1 except the link to the current process is also created.

start_link(name, options)

The same as start/2 except the link to the current process is also created.

stop(instance)

Stop Ruby instance

Macros

call(instance, expression, list)

Call Ruby function.

Parameters

  • instance: pid witch is returned by one of the start function
  • expression: function expression to execute in ruby world
  • from_file: file to run ruby function from

Example

# call "upcase" method from "test" file with "hello" argument
ruby |> Ruby.call(upcase("hello"), from_file: "test")