Struct ruru::Proc [] [src]

pub struct Proc {
    // some fields omitted
}

Proc (works with Lambda as well)

Methods

impl Proc
[src]

fn call(&self, arguments: Vec<AnyObject>) -> AnyObject

Calls a proc with given arguments

Examples

#[macro_use]
extern crate ruru;

use ruru::{Class, Proc, RString};
use ruru::traits::Object;

class!(Greeter);

methods!(
    Greeter,
    itself,

    fn greet_rust_with(greeting_template: Proc) -> RString {
        let name = RString::new("Rust").to_any_object();

        greeting_template.call(vec![name]).to::<RString>()
    }
);

fn main() {
    Class::new("Greeter").define(|itself| {
        itself.def_self("greet_rust_with", greet_rust_with);
    });
}

Ruby:

class Greeter
  def self.greet_rust_with(greeting_template)
    greeting_template.call('Rust')
  end
end

greeting_template = -> (name) { "Hello, #{name}!" }

Greeter.greet_rust_with(greeting_template) # => "Hello, Rust!"

Trait Implementations

impl From<Value> for Proc
[src]

fn from(value: Value) -> Self

Performs the conversion.

impl Object for Proc
[src]

fn value(&self) -> Value

Usually this function just returns a value of current object. Read more

fn class(&self) -> Class

Returns a Class struct of current object Read more

fn send(&self, method: &str, arguments: Vec<AnyObject>) -> AnyObject

Calls a given method on an object similarly to Ruby Object#send method Read more

fn is_nil(&self) -> bool

Checks weather the object is nil Read more

fn to_any_object(&self) -> AnyObject

Converts struct to AnyObject Read more

fn instance_variable_get(&self, variable: &str) -> AnyObject

Sets an instance variable for object Read more

fn instance_variable_set<T: Object>(&mut self, variable: &str, value: T) -> AnyObject

Gets an instance variable of object Read more