pub struct RRational(/* private fields */);
Expand description
Implementations§
source§impl RRational
impl RRational
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(RRational)
if val
is a RRational
, None
otherwise.
§Examples
use magnus::{eval, RRational};
assert!(RRational::from_value(eval("1/2r").unwrap()).is_some());
assert!(RRational::from_value(eval("0.5").unwrap()).is_none());
sourcepub fn new(num: i64, den: NonZeroI64) -> Self
pub fn new(num: i64, den: NonZeroI64) -> Self
Create a new RRational
.
§Panics
Panics if called from a non-Ruby thread. See Ruby::rational_new
for
the non-panicking version.
§Examples
use std::num::NonZeroI64;
use magnus::RRational;
let rational = RRational::new(2, NonZeroI64::new(4).unwrap());
assert_eq!(rational.to_string(), "1/2");
Trait Implementations§
source§impl Numeric for RRational
impl Numeric for RRational
source§fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§impl ReprValue for RRational
impl ReprValue for RRational
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,
Checks for equality, delegating to the Ruby method
#==
. 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,
Checks for equality, delegating to the Ruby method
#eql?
. Read moresource§fn hash(self) -> Result<Integer, Error>
fn hash(self) -> Result<Integer, Error>
Returns an integer non-uniquely identifying
self
. Read moresource§fn to_bool(self) -> bool
fn to_bool(self) -> bool
Convert
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,
Check if
self
responds to the given Ruby method. Read moresource§fn is_kind_of<T>(self, class: T) -> bool
fn is_kind_of<T>(self, class: T) -> bool
source§fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator ⓘwhere
M: IntoSymbol,
A: ArgList,
fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator ⓘwhere
M: IntoSymbol,
A: ArgList,
source§impl TryConvert for RRational
impl TryConvert for RRational
impl Copy for RRational
Auto Trait Implementations§
impl Freeze for RRational
impl RefUnwindSafe for RRational
impl Send for RRational
impl Sync for RRational
impl Unpin for RRational
impl UnwindSafe for RRational
Blanket Implementations§
source§impl<T> AsRawValue for Twhere
T: ReprValue,
impl<T> AsRawValue for Twhere
T: ReprValue,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more