Struct ruru::Array [] [src]

pub struct Array {
    // some fields omitted
}

Array

Methods

impl Array
[src]

fn new() -> Self

Creates a new instance of empty Array.

Examples

use ruru::{Array, VM};

Array::new();

Ruby:

[]

fn at(&self, index: i64) -> AnyObject

Retrieves an AnyObject from element at index position.

Examples

use ruru::{Array, Fixnum, VM};

let array = Array::new().push(Fixnum::new(1));

assert_eq!(array.at(0).as_fixnum(), Fixnum::new(1));

Ruby:

array = [1]

array[0] == 1

fn join(&self, separator: RString) -> RString

Joins all elements of Array to Ruby String.

Examples

use ruru::{Array, RString, VM};

let array =
    Array::new()
        .push(RString::new("Hello"))
        .push(RString::new("World!"));

let joined_string = array.join(RString::new(", ")).to_string();

assert_eq!(joined_string, "Hello, World!".to_string());

Ruby:

array = ['Hello', 'World!']

array.join(', ') == 'Hello, World!'

fn push<T: Object>(&mut self, item: T) -> Self

Pushes an object to Array.

Examples

use ruru::{Array, Fixnum, VM};

let mut array = Array::new();

array.push(Fixnum::new(1));

assert_eq!(array.at(0).as_fixnum(), Fixnum::new(1));

Ruby:

array = []
array << 1

array[0] == 1

fn store<T: Object>(&mut self, index: i64, item: T) -> AnyObject

Stores an object at index position.

Examples

use ruru::{Array, Fixnum, VM};

let mut array = Array::new().push(Fixnum::new(1));

array.store(0, Fixnum::new(2));

assert_eq!(array.at(0).as_fixnum(), Fixnum::new(2));

Ruby:

array = [1]
array[0] = 2

array[0] == 2

Trait Implementations

impl From<Value> for Array
[src]

fn from(value: Value) -> Self

Performs the conversion.

impl Object for Array
[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 as_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