Struct mrusty::Module [] [src]

pub struct Module { /* fields omitted */ }

A struct that wraps around an mruby Module.

Examples

let mruby = Mruby::new();

let module = mruby.def_module("Container");

assert_eq!(module.to_str(), "Container");

Methods

impl Module
[src]

Includes a Module in a Module.

Examples

let mruby = Mruby::new();

mruby.run("
  module Increment
    def inc
      self + 1
    end
  end

  module Increment2; end
").unwrap();

let fixnum = mruby.get_class("Fixnum").unwrap();
let increment = mruby.get_module("Increment").unwrap();
let increment2 = mruby.get_module("Increment2").unwrap();

increment2.include(increment);
fixnum.include(increment2);

let result = mruby.run("1.inc").unwrap();

assert_eq!(result.to_i32().unwrap(), 2);

Defines constant with name name and value value on a Module.

Examples

let mruby = Mruby::new();

mruby.run("
  module Container; end
").unwrap();

let cont = mruby.get_module("Container").unwrap();

cont.def_const("ONE", mruby.fixnum(1));

let result = mruby.run("Container::ONE").unwrap();

assert_eq!(result.to_i32().unwrap(), 1);

Returns a &str with the mruby Module name.

Examples

let mruby = Mruby::new();

let module = mruby.def_module("Container");

assert_eq!(module.to_str(), "Container");

Casts Module to Value.

Examples

let mruby = Mruby::new();

let module = mruby.def_module("Container");
let value = module.to_value();

let name = value.call("to_s", vec![]).unwrap();

assert_eq!(name.to_str().unwrap(), "Container");

Trait Implementations

impl ClassLike for Module
[src]

impl Clone for Module
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq<Module> for Module
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Debug for Module
[src]

Formats the value using the given formatter.