Struct ruru::Proc [] [src]

pub struct Proc { /* fields omitted */ }

Proc (works with Lambda as well)

Methods

impl Proc
[src]

Calls a proc with given arguments

Examples

#[macro_use]
extern crate ruru;

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

class!(Greeter);

methods!(
    Greeter,
    itself,

    fn greet_rust_with(greeting_template: Proc) -> RString {
        let name = RString::new("Rust").to_any_object();
        let rendered_template = greeting_template.unwrap().call(vec![name]);

        rendered_template.try_convert_to::<RString>().unwrap()
    }
);

fn main() {
    Class::new("Greeter", None).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 Debug for Proc
[src]

Formats the value using the given formatter.

impl PartialEq for Proc
[src]

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

This method tests for !=.

impl From<Value> for Proc
[src]

Performs the conversion.

impl Object for Proc
[src]

Returns internal value of current object. Read more

Returns a class of current object. Read more

Returns a singleton class of current object. Read more

Gets a Rust structure that is wrapped into a Ruby object. Read more

Wraps calls to the object. Read more

Defines an instance method for the given class or object. Read more

Defines a class method for given class or singleton method for object. Read more

An alias for define_method (similar to Ruby syntax def some_method).

An alias for define_singleton_method (similar to Ruby def self.some_method).

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

Checks whether the object responds to given method Read more

Checks whether the object is nil Read more

Converts struct to AnyObject Read more

Gets an instance variable of object Read more

Sets an instance variable for object Read more

Returns the freeze status of the object. Read more

Prevents further modifications to the object. Read more

Unsafely casts current object to the specified Ruby type Read more

Safely casts current object to the specified Ruby type Read more

Determines the value type of the object Read more

impl VerifiedObject for Proc
[src]