pub struct RArray(/* private fields */);
Expand description
Implementations§
source§impl RArray
impl RArray
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(RArray)
if val
is a RArray
, None
otherwise.
§Examples
use magnus::{eval, RArray};
assert!(RArray::from_value(eval(r#"[true, 0, "example"]"#).unwrap()).is_some());
assert!(RArray::from_value(eval(r#"{"answer" => 42}"#).unwrap()).is_none());
assert!(RArray::from_value(eval(r"nil").unwrap()).is_none());
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty RArray
.
§Panics
Panics if called from a non-Ruby thread. See Ruby::ary_new
for the
non-panicking version.
§Examples
use magnus::RArray;
let ary = RArray::new();
assert!(ary.is_empty());
sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create a new empty RArray
with capacity for n
elements
pre-allocated.
§Panics
Panics if called from a non-Ruby thread. See Ruby::ary_new_capa
for
the non-panicking version.
§Examples
use magnus::RArray;
let ary = RArray::with_capacity(16);
assert!(ary.is_empty());
sourcepub fn to_ary(val: Value) -> Result<Self, Error>
pub fn to_ary(val: Value) -> Result<Self, Error>
Convert or wrap a Ruby Value
to a RArray
.
If val
responds to #to_ary
calls that and passes on the returned
array, otherwise returns a single element array containing val
.
§Examples
use magnus::{rb_assert, IntoValue, RArray};
let ary = RArray::to_ary(1.into_value()).unwrap();
rb_assert!("[1] == ary", ary);
let ary = RArray::to_ary(vec![1, 2, 3].into_value()).unwrap();
rb_assert!("[1, 2, 3] == ary", ary);
This can fail in the case of a misbehaving #to_ary
method:
use magnus::{eval, RArray};
let val = eval(
r#"
o = Object.new
def o.to_ary
"not an array"
end
o
"#,
)
.unwrap();
assert!(RArray::to_ary(val).is_err());
sourcepub fn dup(self) -> Self
pub fn dup(self) -> Self
Create a new RArray
that is a duplicate of self
.
The new array is only a shallow clone.
§Examples
use magnus::{rb_assert, RArray};
let a = RArray::from_vec(vec![1, 2, 3]);
let b = a.dup();
rb_assert!("a == b", a, b);
a.push(4).unwrap();
b.push(5).unwrap();
rb_assert!("a == [1, 2, 3, 4]", a);
rb_assert!("b == [1, 2, 3, 5]", b);
sourcepub fn is_empty(self) -> bool
pub fn is_empty(self) -> bool
Return whether self contains any entries or not.
§Examples
use magnus::RArray;
let ary = RArray::new();
assert!(ary.is_empty());
ary.push("foo").unwrap();
assert!(!ary.is_empty());
sourcepub fn includes<T>(self, val: T) -> boolwhere
T: IntoValue,
pub fn includes<T>(self, val: T) -> boolwhere
T: IntoValue,
Returns true
if val
is in self
, false
otherwise.
§Examples
use magnus::{eval, value::qnil, RArray, Symbol};
let ary: RArray = eval(r#"[:foo, "bar", 2]"#).unwrap();
assert!(ary.includes(Symbol::new("foo")));
assert!(ary.includes("bar"));
assert!(ary.includes(2));
// 2.0 == 2 in Ruby
assert!(ary.includes(2.0));
assert!(!ary.includes("foo"));
assert!(!ary.includes(qnil()));
sourcepub fn cat<T>(self, s: &[T]) -> Result<(), Error>where
T: ReprValue,
pub fn cat<T>(self, s: &[T]) -> Result<(), Error>where
T: ReprValue,
Concatenate elements from the slice s
to self
.
Returns Err
if self
is frozen.
§Examples
use magnus::{prelude::*, rb_assert, value::qnil, Integer, RArray, Symbol};
let ary = RArray::new();
ary.cat(&[
Symbol::new("a").as_value(),
Integer::from_i64(1).as_value(),
qnil().as_value(),
])
.unwrap();
rb_assert!("ary == [:a, 1, nil]", ary);
use magnus::{rb_assert, RArray, Symbol};
let ary = RArray::new();
ary.cat(&[Symbol::new("a"), Symbol::new("b"), Symbol::new("c")])
.unwrap();
rb_assert!("ary == [:a, :b, :c]", ary);
sourcepub fn concat(self, other: Self) -> Result<(), Error>
pub fn concat(self, other: Self) -> Result<(), Error>
Concatenate elements from Ruby array other
to self
.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray};
let a = RArray::from_vec(vec![1, 2, 3]);
let b = RArray::from_vec(vec!["a", "b", "c"]);
a.concat(b).unwrap();
rb_assert!(r#"a == [1, 2, 3, "a", "b", "c"]"#, a);
rb_assert!(r#"b == ["a", "b", "c"]"#, b);
sourcepub fn plus(self, other: Self) -> Self
pub fn plus(self, other: Self) -> Self
Create a new RArray
containing the both the elements in self
and
other
.
§Examples
use magnus::{rb_assert, RArray};
let a = RArray::from_vec(vec![1, 2, 3]);
let b = RArray::from_vec(vec!["a", "b", "c"]);
let c = a.plus(b);
rb_assert!(r#"c == [1, 2, 3, "a", "b", "c"]"#, c);
rb_assert!(r#"a == [1, 2, 3]"#, a);
rb_assert!(r#"b == ["a", "b", "c"]"#, b);
sourcepub fn from_slice<T>(slice: &[T]) -> Selfwhere
T: ReprValue,
pub fn from_slice<T>(slice: &[T]) -> Selfwhere
T: ReprValue,
Create a new RArray
containing the elements in slice
.
§Panics
Panics if called from a non-Ruby thread. See
Ruby::ary_new_from_values
for the non-panicking version.
§Examples
use magnus::{prelude::*, rb_assert, value::qnil, Integer, RArray, Symbol};
let ary = RArray::from_slice(&[
Symbol::new("a").as_value(),
Integer::from_i64(1).as_value(),
qnil().as_value(),
]);
rb_assert!("ary == [:a, 1, nil]", ary);
use magnus::{rb_assert, RArray, Symbol};
let ary = RArray::from_slice(&[Symbol::new("a"), Symbol::new("b"), Symbol::new("c")]);
rb_assert!("ary == [:a, :b, :c]", ary);
sourcepub fn push<T>(self, item: T) -> Result<(), Error>where
T: IntoValue,
pub fn push<T>(self, item: T) -> Result<(), Error>where
T: IntoValue,
Add item
to the end of self
.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray, Symbol};
let ary = RArray::new();
ary.push(Symbol::new("a")).unwrap();
ary.push(1).unwrap();
ary.push(()).unwrap();
rb_assert!("ary == [:a, 1, nil]", ary);
sourcepub fn pop<T>(self) -> Result<T, Error>where
T: TryConvert,
pub fn pop<T>(self) -> Result<T, Error>where
T: TryConvert,
Remove and return the last element of self
, converting it to a T
.
Errors if self
is frozen or if the conversion fails.
§Examples
use magnus::{eval, RArray};
let ary: RArray = eval("[1, 2, 3]").unwrap();
assert_eq!(ary.pop::<i64>().unwrap(), 3);
assert_eq!(ary.pop::<i64>().unwrap(), 2);
assert_eq!(ary.pop::<i64>().unwrap(), 1);
assert!(ary.pop::<i64>().is_err());
use magnus::{eval, RArray};
let ary: RArray = eval("[1, 2, 3]").unwrap();
assert_eq!(ary.pop::<Option<i64>>().unwrap(), Some(3));
assert_eq!(ary.pop::<Option<i64>>().unwrap(), Some(2));
assert_eq!(ary.pop::<Option<i64>>().unwrap(), Some(1));
assert_eq!(ary.pop::<Option<i64>>().unwrap(), None);
sourcepub fn unshift<T>(self, item: T) -> Result<(), Error>where
T: IntoValue,
pub fn unshift<T>(self, item: T) -> Result<(), Error>where
T: IntoValue,
Add item
to the beginning of self
.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray, Symbol};
let ary = RArray::new();
ary.unshift(Symbol::new("a")).unwrap();
ary.unshift(1).unwrap();
ary.unshift(()).unwrap();
rb_assert!("ary == [nil, 1, :a]", ary);
sourcepub fn shift<T>(self) -> Result<T, Error>where
T: TryConvert,
pub fn shift<T>(self) -> Result<T, Error>where
T: TryConvert,
Remove and return the first element of self
, converting it to a T
.
Errors if self
is frozen or if the conversion fails.
§Examples
use magnus::{eval, RArray};
let ary: RArray = eval("[1, 2, 3]").unwrap();
assert_eq!(ary.shift::<i64>().unwrap(), 1);
assert_eq!(ary.shift::<i64>().unwrap(), 2);
assert_eq!(ary.shift::<i64>().unwrap(), 3);
assert!(ary.shift::<i64>().is_err());
use magnus::{eval, RArray};
let ary: RArray = eval("[1, 2, 3]").unwrap();
assert_eq!(ary.shift::<Option<i64>>().unwrap(), Some(1));
assert_eq!(ary.shift::<Option<i64>>().unwrap(), Some(2));
assert_eq!(ary.shift::<Option<i64>>().unwrap(), Some(3));
assert_eq!(ary.shift::<Option<i64>>().unwrap(), None);
sourcepub fn delete<T>(self, item: T) -> Result<(), Error>where
T: IntoValue,
pub fn delete<T>(self, item: T) -> Result<(), Error>where
T: IntoValue,
Remove all elements from self
that match item
’s ==
method.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec(vec![1, 1, 2, 3]);
ary.delete(1).unwrap();
rb_assert!("ary == [2, 3]", ary);
sourcepub fn delete_at<T>(self, index: isize) -> Result<T, Error>where
T: TryConvert,
pub fn delete_at<T>(self, index: isize) -> Result<T, Error>where
T: TryConvert,
Remove and return the element of self
at index
, converting it to a
T
.
index
may be negative, in which case it counts backward from the end
of the array.
Returns Err
if self
is frozen or if the conversion fails.
The returned element will be Ruby’s nil
when index
is out of bounds
this makes it impossible to distingush between out of bounds and
removing nil
without an additional length check.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec(vec!["a", "b", "c"]);
let removed: Option<String> = ary.delete_at(1).unwrap();
assert_eq!(removed, Some(String::from("b")));
rb_assert!(r#"ary == ["a", "c"]"#, ary);
sourcepub fn clear(self) -> Result<(), Error>
pub fn clear(self) -> Result<(), Error>
Remove all elements from self
Returns Err
if self
is frozen.
§Examples
use magnus::RArray;
let ary = RArray::from_vec::<i64>(vec![1, 2, 3]);
assert!(!ary.is_empty());
ary.clear().unwrap();
assert!(ary.is_empty());
sourcepub fn resize(self, len: usize) -> Result<(), Error>
pub fn resize(self, len: usize) -> Result<(), Error>
Expand or shrink the length of self
.
When increasing the length of the array empty positions will be filled
with nil
.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec::<i64>(vec![1, 2, 3]);
ary.resize(5).unwrap();
rb_assert!("ary == [1, 2, 3, nil, nil]", ary);
ary.resize(2).unwrap();
rb_assert!("ary == [1, 2]", ary);
sourcepub fn reverse(self) -> Result<(), Error>
pub fn reverse(self) -> Result<(), Error>
Reverses the order of self
in place.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec::<i64>(vec![1, 2, 3]);
ary.reverse().unwrap();
rb_assert!("ary == [3, 2, 1]", ary);
sourcepub fn rotate(self, rot: isize) -> Result<(), Error>
pub fn rotate(self, rot: isize) -> Result<(), Error>
Rotates the elements of self
in place by rot
positions.
If rot
is positive elements are rotated to the left, if negative,
to the right.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec::<i64>(vec![1, 2, 3, 4, 5, 6, 7]);
ary.rotate(3).unwrap();
rb_assert!("ary == [4, 5, 6, 7, 1, 2, 3]", ary);
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec::<i64>(vec![1, 2, 3, 4, 5, 6, 7]);
ary.rotate(-3).unwrap();
rb_assert!("ary == [5, 6, 7, 1, 2, 3, 4]", ary);
sourcepub fn sort(self) -> Result<(), Error>
pub fn sort(self) -> Result<(), Error>
Storts the elements of self
in place using Ruby’s <=>
operator.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec::<i64>(vec![2, 1, 3]);
ary.sort().unwrap();
rb_assert!("ary == [1, 2, 3]", ary);
sourcepub fn from_vec<T>(vec: Vec<T>) -> Selfwhere
T: IntoValueFromNative,
pub fn from_vec<T>(vec: Vec<T>) -> Selfwhere
T: IntoValueFromNative,
Create a new RArray
from a Rust vector.
§Panics
Panics if called from a non-Ruby thread. See Ruby::ary_from_vec
for
the non-panicking version.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec(vec![1, 2, 3]);
rb_assert!("ary == [1, 2, 3]", ary);
sourcepub unsafe fn as_slice(&self) -> &[Value]
pub unsafe fn as_slice(&self) -> &[Value]
Return self
as a slice of Value
s.
§Safety
This is directly viewing memory owned and managed by Ruby. Ruby may modify or free the memory backing the returned slice, the caller must ensure this does not happen.
Ruby must not be allowed to garbage collect or modify self
while a
refrence to the slice is held.
§Examples
use magnus::{eval, rb_assert, RArray};
let ary: RArray = eval("[1, 2, 3, 4, 5]").unwrap();
// must not call any Ruby api that may modify ary while we have a
// refrence to the return value of ::from_slice()
unsafe {
let middle = RArray::from_slice(&ary.as_slice()[1..4]);
rb_assert!("middle == [2, 3, 4]", middle);
}
sourcepub fn to_vec<T>(self) -> Result<Vec<T>, Error>where
T: TryConvertOwned,
pub fn to_vec<T>(self) -> Result<Vec<T>, Error>where
T: TryConvertOwned,
Convert self
to a Rust vector of T
s. Errors if converting any
element in the array fails.
This will only convert to a map of ‘owned’ Rust native types. The types
representing Ruby objects can not be stored in a heap-allocated
datastructure like a Vec
as they are hidden from the mark phase
of Ruby’s garbage collector, and thus may be prematurely garbage
collected in the following sweep phase.
§Examples
use magnus::{eval, RArray};
let ary: RArray = eval("[1, 2, 3]").unwrap();
assert_eq!(ary.to_vec::<i64>().unwrap(), vec![1, 2, 3]);
sourcepub fn to_value_array<const N: usize>(self) -> Result<[Value; N], Error>
pub fn to_value_array<const N: usize>(self) -> Result<[Value; N], Error>
Convert self
to a Rust array of Value
s, of length N
.
Errors if the Ruby array is not of length N
.
§Examples
use magnus::{eval, RArray};
let ary: RArray = eval("[1, 2, 3]").unwrap();
assert!(ary.to_value_array::<3>().is_ok());
assert!(ary.to_value_array::<2>().is_err());
assert!(ary.to_value_array::<4>().is_err());
sourcepub fn to_array<T, const N: usize>(self) -> Result<[T; N], Error>where
T: TryConvert,
pub fn to_array<T, const N: usize>(self) -> Result<[T; N], Error>where
T: TryConvert,
Convert self
to a Rust array of T
s, of length N
.
Errors if converting any element in the array fails, or if the Ruby
array is not of length N
.
§Examples
use magnus::{eval, RArray};
let ary: RArray = eval("[1, 2, 3]").unwrap();
assert_eq!(ary.to_array::<i64, 3>().unwrap(), [1, 2, 3]);
assert!(ary.to_array::<i64, 2>().is_err());
assert!(ary.to_array::<i64, 4>().is_err());
sourcepub fn join<T>(self, sep: T) -> Result<RString, Error>where
T: IntoRString,
pub fn join<T>(self, sep: T) -> Result<RString, Error>where
T: IntoRString,
Stringify the contents of self
and join the sequence with sep
.
§Examples
use magnus::{prelude::*, value::qnil, Integer, RArray, Symbol};
let ary = RArray::from_slice(&[
Symbol::new("a").as_value(),
Integer::from_i64(1).as_value(),
qnil().as_value(),
]);
assert_eq!(ary.join(", ").unwrap().to_string().unwrap(), "a, 1, ")
sourcepub fn entry<T>(self, offset: isize) -> Result<T, Error>where
T: TryConvert,
pub fn entry<T>(self, offset: isize) -> Result<T, Error>where
T: TryConvert,
Return the element at offset
, converting it to a T
.
Errors if the conversion fails.
An offset out of range will return nil
.
§Examples
use magnus::{eval, RArray};
let ary: RArray = eval(r#"["a", "b", "c"]"#).unwrap();
assert_eq!(ary.entry::<String>(0).unwrap(), String::from("a"));
assert_eq!(ary.entry::<char>(0).unwrap(), 'a');
assert_eq!(
ary.entry::<Option<String>>(0).unwrap(),
Some(String::from("a"))
);
assert_eq!(ary.entry::<String>(1).unwrap(), String::from("b"));
assert_eq!(ary.entry::<String>(-1).unwrap(), String::from("c"));
assert_eq!(ary.entry::<Option<String>>(3).unwrap(), None);
assert!(ary.entry::<i64>(0).is_err());
assert!(ary.entry::<String>(3).is_err());
sourcepub fn store<T>(self, offset: isize, val: T) -> Result<(), Error>where
T: IntoValue,
pub fn store<T>(self, offset: isize, val: T) -> Result<(), Error>where
T: IntoValue,
Set the element at offset
.
If offset
is beyond the current size of the array the array will be
expanded and padded with nil
.
Returns Err
if self
is frozen.
§Examples
use magnus::{rb_assert, RArray, Symbol};
let ary = RArray::from_slice(&[Symbol::new("a"), Symbol::new("b"), Symbol::new("c")]);
ary.store(0, Symbol::new("d")).unwrap();
ary.store(5, Symbol::new("e")).unwrap();
ary.store(6, Symbol::new("f")).unwrap();
ary.store(-1, Symbol::new("g")).unwrap();
rb_assert!("ary == [:d, :b, :c, nil, nil, :e, :g]", ary);
sourcepub fn each(self) -> Enumerator ⓘ
pub fn each(self) -> Enumerator ⓘ
Returns an Enumerator
over self
.
§Examples
use magnus::{eval, prelude::*, RArray};
let mut res = Vec::new();
for i in eval::<RArray>("[1, 2, 3]").unwrap().each() {
res.push(i64::try_convert(i.unwrap()).unwrap());
}
assert_eq!(res, vec![1, 2, 3]);
Returns true if both self
and other
share the same backing storage.
It is possible for two Ruby Arrays to share the same backing storage, and only when one of them is modified will the copy-on-write cost be paid.
Currently, this method will only return true
if self
and other
are of the same length, even though Ruby may continue to use the same
backing storage after popping a value from either of the arrays.
§Examples
use magnus::RArray;
let ary = RArray::from_vec((0..256).collect());
let copy = RArray::new();
copy.replace(ary).unwrap();
assert!(ary.is_shared(copy));
assert!(copy.is_shared(ary));
copy.push(11).unwrap();
assert!(!ary.is_shared(copy));
assert!(!copy.is_shared(ary));
sourcepub fn replace(self, from: Self) -> Result<(), Error>
pub fn replace(self, from: Self) -> Result<(), Error>
Replace the contents of self
with from
.
from
is unmodified, and self
becomes a copy of from
. self
’s
former contents are abandoned.
This is a very cheap operation, self
will point at from
’s backing
storage until one is modified, and only then will the copy-on-write
cost be paid.
Returns Err
if self
is frozen.
§Examples
use magnus::RArray;
let ary = RArray::from_vec((0..256).collect());
let copy = RArray::new();
copy.replace(ary).unwrap();
assert!(copy.is_shared(ary));
copy.push(11).unwrap();
assert!(!copy.is_shared(ary));
sourcepub fn subseq(self, offset: usize, length: usize) -> Option<Self>
pub fn subseq(self, offset: usize, length: usize) -> Option<Self>
Create a new array from a subsequence of self
.
This is a very cheap operation, as self
and the new array will share
their backing storage until one is modified.
§Examples
use magnus::{rb_assert, RArray};
let ary = RArray::from_vec(vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let a = ary.subseq(0, 5).unwrap();
let b = ary.subseq(5, 5).unwrap();
rb_assert!("a == [1, 2, 3, 4, 5]", a);
rb_assert!("b == [6, 7, 8, 9, 10]", b);
sourcepub fn assoc<K, T>(self, key: K) -> Result<T, Error>where
K: IntoValue,
T: TryConvert,
pub fn assoc<K, T>(self, key: K) -> Result<T, Error>where
K: IntoValue,
T: TryConvert,
Search self
as an ‘associative array’ for key
.
Assumes self
is an array of arrays, searching from the start of the
outer array, returns the first inner array where the first element
matches key
.
§Examples
use magnus::RArray;
let ary = RArray::from_vec(vec![("foo", 1), ("bar", 2), ("baz", 3), ("baz", 4)]);
assert_eq!(
ary.assoc::<_, (String, i64)>("baz").unwrap(),
(String::from("baz"), 3)
);
assert_eq!(ary.assoc::<_, Option<(String, i64)>>("quz").unwrap(), None);
sourcepub fn rassoc<K, T>(self, value: K) -> Result<T, Error>where
K: IntoValue,
T: TryConvert,
pub fn rassoc<K, T>(self, value: K) -> Result<T, Error>where
K: IntoValue,
T: TryConvert,
Search self
as an ‘associative array’ for value
.
Assumes self
is an array of arrays, searching from the start of the
outer array, returns the first inner array where the second element
matches value
.
§Examples
use magnus::RArray;
let ary = RArray::from_vec(vec![("foo", 1), ("bar", 2), ("baz", 3), ("qux", 3)]);
assert_eq!(
ary.rassoc::<_, (String, i64)>(3).unwrap(),
(String::from("baz"), 3)
);
assert_eq!(ary.rassoc::<_, Option<(String, i64)>>(4).unwrap(), None);
sourcepub fn cmp(self, other: Self) -> Result<Option<Ordering>, Error>
pub fn cmp(self, other: Self) -> Result<Option<Ordering>, Error>
Recursively compares elements of the two arrays using Ruby’s <=>
.
Returns Some(Ordering::Equal)
if self
and other
are equal.
Returns Some(Ordering::Less)
if self
if less than other
.
Returns Some(Ordering::Greater)
if self
if greater than other
.
Returns None
if self
and other
are not comparable.
§Examples
use std::cmp::Ordering;
use magnus::RArray;
let a = RArray::from_vec(vec![1, 2, 3]);
let b = RArray::from_vec(vec![1, 2, 3]);
assert_eq!(a.cmp(b).unwrap(), Some(Ordering::Equal));
let c = RArray::from_vec(vec![1, 2, 0]);
assert_eq!(a.cmp(c).unwrap(), Some(Ordering::Greater));
let d = RArray::from_vec(vec![1, 2, 4]);
assert_eq!(a.cmp(d).unwrap(), Some(Ordering::Less));
let e = RArray::from_vec(vec![1, 2]);
e.push(()).unwrap();
assert_eq!(a.cmp(e).unwrap(), None);
Note that std::cmp::Ordering
can be cast to i{8,16,32,64,size}
to
get the Ruby standard -1
/0
/+1
for comparison results.
assert_eq!(std::cmp::Ordering::Less as i64, -1);
assert_eq!(std::cmp::Ordering::Equal as i64, 0);
assert_eq!(std::cmp::Ordering::Greater as i64, 1);
Trait Implementations§
source§impl<T> FromIterator<T> for RArraywhere
T: IntoValue,
impl<T> FromIterator<T> for RArraywhere
T: IntoValue,
source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Creates a Ruby array from an iterator.
§Panics
Panics if called from a non-Ruby thread. See Ruby::ary_from_iter
for the non-panicking version.
source§impl Object for RArray
impl Object for RArray
source§fn define_singleton_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
fn define_singleton_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
self
’s scope. Read moresource§impl RArrayArgList for RArray
impl RArrayArgList for RArray
source§fn into_array_arg_list_with(self, _: &Ruby) -> RArray
fn into_array_arg_list_with(self, _: &Ruby) -> RArray
self
into a type that can be used as a Ruby Proc argument
list.source§fn contains_kw_args(&self) -> bool
fn contains_kw_args(&self) -> bool
RArray
produced by
Self::into_array_arg_list_with
must be a RHash
source§impl ReprValue for RArray
impl ReprValue for RArray
source§fn equal<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
fn equal<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
#==
. Read moresource§fn eql<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
fn eql<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
#eql?
. Read moresource§fn hash(self) -> Result<Integer, Error>
fn hash(self) -> Result<Integer, Error>
self
. Read moresource§fn to_bool(self) -> bool
fn to_bool(self) -> bool
self
to a bool
, following Ruby’s rules of false
and nil
as boolean false
and everything else boolean true
. Read moresource§fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
source§fn block_call<M, A, R, T>(
self,
method: M,
args: A,
block: fn(_: &[Value], _: Option<Proc>) -> R
) -> Result<T, Error>
fn block_call<M, A, R, T>( self, method: M, args: A, block: fn(_: &[Value], _: Option<Proc>) -> R ) -> Result<T, Error>
source§fn respond_to<M>(self, method: M, include_private: bool) -> Result<bool, Error>where
M: IntoId,
fn respond_to<M>(self, method: M, include_private: bool) -> Result<bool, Error>where
M: IntoId,
self
responds to the given Ruby method. Read more