Struct mrusty::Class [] [src]

pub struct Class {
    // some fields omitted
}

A struct that wraps around an mruby Class.

Examples

let mruby = Mruby::new();

struct Cont;

let class = mruby.def_class_for::<Cont>("Container");

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

Methods

impl Class
[src]

fn include(&self, module: Module)

Includes a Module in a Class.

Examples

let mruby = Mruby::new();

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

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

fixnum.include(increment);

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

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

fn def_const(&self, name: &str, value: Value)

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

Examples

let mruby = Mruby::new();

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

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

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

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

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

fn to_str(&self) -> &str

Returns a &str with the mruby Class name.

Examples

let mruby = Mruby::new();

struct Cont;

let class = mruby.def_class_for::<Cont>("Container");

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

fn to_value(&self) -> Value

Casts Class to Value.

Examples

let mruby = Mruby::new();

struct Cont;

let class = mruby.def_class_for::<Cont>("Container");
let value = class.to_value();

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

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

Trait Implementations

impl ClassLike for Class
[src]

fn class(&self) -> *const MrClass

impl Clone for Class
[src]

fn clone(&self) -> Class

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl PartialEq<Class> for Class
[src]

fn eq(&self, other: &Class) -> bool

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

fn ne(&self, other: &Rhs) -> bool
1.0.0

This method tests for !=.

impl Debug for Class
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.