ruby_runtime 0.0.1 copy "ruby_runtime: ^0.0.1" to clipboard
ruby_runtime: ^0.0.1 copied to clipboard

Embedded mruby runtime plugin for Flutter (Android/iOS).

ruby_runtime #

Embedded mruby runtime plugin for Flutter.

ruby_runtime exposes a simple Dart API:

  • RubyRuntime.initialize()
  • RubyRuntime.eval(String code)
  • RubyRuntime.runFile(String path)
  • RubyRuntime.reset()

Usage #

1. Initialize runtime #

import 'package:ruby_runtime/ruby_runtime.dart';

Future<void> setupRuby() async {
  await RubyRuntime.initialize();
}

2. Execute Ruby code #

Future<String> runCode() async {
  final result = await RubyRuntime.eval('"Hello, " + "mruby"');
  return result; // => "Hello, mruby"
}

3. Run a Ruby file #

import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:ruby_runtime/ruby_runtime.dart';

Future<String> runRubyFile() async {
  final dir = await getTemporaryDirectory();
  final file = File('${dir.path}/sample.rb');
  await file.writeAsString('class Calc\n  def add(a, b)\n    a + b\n  end\nend\nCalc.new.add(10, 20)');

  return RubyRuntime.runFile(file.path); // => "30"
}

4. Reset runtime (optional) #

Future<void> resetRuby() async {
  await RubyRuntime.reset();
}

Notes #

  • This runtime is mruby, not CRuby.
  • Not all Ruby stdlib APIs are available by default.
  • Socket/IO support is provided via mruby gems included in the plugin.
0
likes
120
points
68
downloads

Publisher

unverified uploader

Weekly Downloads

Embedded mruby runtime plugin for Flutter (Android/iOS).

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ruby_runtime

Packages that implement ruby_runtime