Struct Module

Source
pub struct Module(/* private fields */);
Expand description

An instance of Ruby’s Module type.

Implementations§

Source§

impl Module

Source

pub fn extend(self, object: impl Object) -> Result

Extends object with the contents of self.

Source

pub unsafe fn extend_unchecked(self, object: impl Object)

Extends object with the contents of self.

§Safety

The caller must ensure that self is not frozen or else a FrozenError exception will be raised.

Source

pub fn def(name: impl Into<SymbolId>) -> Result<Self, DefMixinError>

Defines a new top-level module with name.

§Examples

Defining a new module is straightforward:

let my_mod = rosy::Module::def("MyMod").unwrap();

Attempting to define an existing module will result in an error:

use rosy::Module;

let math = Module::def("Math").unwrap_err().existing_object();
assert_eq!(Module::math(), math.unwrap());
Source

pub fn get(name: impl Into<SymbolId>) -> Option<Self>

Retrieves an existing top-level Module defined by name.

Source

pub unsafe fn get_unchecked(name: impl Into<SymbolId>) -> Self

Retrieves an existing top-level Module defined by name.

§Safety

This method does not:

  • Check whether an item for name exists (an exception will be thrown if this is the case)
  • Check whether the returned item for name is actually a Module
Source

pub fn get_or_def(name: impl Into<SymbolId>) -> Result<Self, DefMixinError>

Retrieves an existing top-level Module defined by name or defines one if it doesn’t exist.

Source

pub fn name(self) -> Option<String>

Returns the name of self or nil if anonymous.

Source

pub fn ancestors(self) -> Array<Module>

Returns the ancestors of this module, including itself.

Source§

impl Module

Built-in modules.

Source

pub fn kernel() -> Self

The Kernel module.

Source

pub fn comparable() -> Self

The Comparable module.

Source

pub fn enumerable() -> Self

The Enumerable module.

Source

pub fn errno() -> Self

The Errno module.

Source

pub fn file_test() -> Self

The FileTest module.

Source

pub fn gc() -> Self

The GC module.

Source

pub fn math() -> Self

The Math module.

Source

pub fn process() -> Self

The Process module.

Source

pub fn wait_readable() -> Self

The WaitReadable module.

Source

pub fn wait_writable() -> Self

The WaitWritable module.

Trait Implementations§

Source§

impl AsRef<AnyObject> for Module

Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Classify for Module

Source§

fn class() -> Class<Self>

Returns the typed class that can be used to get an instance of self.
Source§

impl Clone for Module

Source§

fn clone(&self) -> Module

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Module> for AnyObject

Source§

fn from(object: Module) -> AnyObject

Converts to this type from the input type.
Source§

impl Mixin for Module

Source§

fn to_class(self) -> Result<Class, Module>

Returns self as a Class if it is one or a Module otherwise.
Source§

fn to_module(self) -> Result<Module, Class>

Returns self as a Module if it is one or a Class otherwise.
Source§

fn include(self, module: Module)

Embeds the contents of module in self.
Source§

fn includes(self, module: Module) -> bool

Returns whether self or one of its ancestors includes module. Read more
Source§

fn included_modules(self) -> Array<Module>

Returns an array of the modules included in self.
Source§

fn prepend(self, module: Module)

Prepends module in self.
Source§

fn def_class(self, name: impl Into<SymbolId>) -> Result<Class, DefMixinError>

Defines a new class under self with name.
Source§

fn def_subclass<S: Object>( self, superclass: Class<S>, name: impl Into<SymbolId>, ) -> Result<Class, DefMixinError>

Defines a new subclass of superclass under self with name.
Source§

fn get_class(self, name: impl Into<SymbolId>) -> Option<Class>

Returns the existing Class with name in self.
Source§

unsafe fn get_class_unchecked(self, name: impl Into<SymbolId>) -> Class

Returns the existing Class with name in self. Read more
Source§

fn def_module(self, name: impl Into<SymbolId>) -> Result<Module, DefMixinError>

Defines a new module under self with name.
Source§

fn get_module(self, name: impl Into<SymbolId>) -> Option<Module>

Returns the existing Module with name in self.
Source§

unsafe fn get_module_unchecked(self, name: impl Into<SymbolId>) -> Module

Returns the existing Module with name in self. Read more
Source§

fn has_const(self, name: impl Into<SymbolId>) -> bool

Returns whether a constant for name is defined in self, or in some parent class if not self.
Source§

fn get_const(self, name: impl Into<SymbolId>) -> AnyObject

Returns the constant value for name in self, or in some parent class if not self. Read more
Source§

fn set_const(self, name: impl Into<SymbolId>, val: impl Into<AnyObject>)

Sets the value a constant for name in self to val.
Source§

fn remove_const(self, name: impl Into<SymbolId>) -> AnyObject

Removes the constant value for name, returning it. Read more
Source§

fn has_class_var(self, var: impl Into<SymbolId>) -> bool

Returns whether the class-level var is defined in self.
Source§

fn get_class_var(self, var: impl Into<SymbolId>) -> AnyObject

Returns the class-level var in self. Read more
Source§

fn set_class_var<K, V>(self, key: K, val: V) -> Result
where K: Into<SymbolId>, V: Into<AnyObject>,

Sets the class-level var in self to val.
Source§

unsafe fn set_class_var_unchecked<K, V>(self, key: K, val: V)
where K: Into<SymbolId>, V: Into<AnyObject>,

Sets the class-level var for key in self to val. Read more
Source§

fn def_attr_reader<N: Into<SymbolId>>(self, name: N) -> Result

Defines an read-only attribute on self with name.
Source§

unsafe fn def_attr_reader_unchecked<N: Into<SymbolId>>(self, name: N)

Defines an read-only attribute on self with name. Read more
Source§

fn def_attr_writer<N: Into<SymbolId>>(self, name: N) -> Result

Defines a write-only attribute on self with name.
Source§

unsafe fn def_attr_writer_unchecked<N: Into<SymbolId>>(self, name: N)

Defines a write-only attribute on self with name. Read more
Source§

fn def_attr_accessor<N: Into<SymbolId>>(self, name: N) -> Result

Defines a read-write attribute on self with name.
Source§

unsafe fn def_attr_accessor_unchecked<N: Into<SymbolId>>(self, name: N)

Defines a read-write attribute on self with name. Read more
Source§

unsafe fn eval(self, args: impl EvalArgs) -> AnyObject

Evaluates args in the context of self. Read more
Source§

unsafe fn eval_protected(self, args: impl EvalArgs) -> Result<AnyObject>

Evaluates args in the context of self, returning any raised exceptions. Read more
Source§

impl Object for Module

Source§

fn unique_id() -> Option<u128>

Returns a unique identifier for an object type to facilitate casting. Read more
Source§

fn cast<A: Object>(obj: A) -> Option<Self>

Attempts to create an instance by casting obj. Read more
Source§

fn ty(self) -> Ty

Returns the virtual type of self.
Source§

fn is_ty(self, ty: Ty) -> bool

Returns whether the virtual type of self is ty.
Source§

unsafe fn from_raw(raw: usize) -> Self

Creates a new object from raw without checking. Read more
Source§

unsafe fn cast_unchecked(obj: impl Object) -> Self

Casts obj to Self without checking its type.
Source§

fn into_any_object(self) -> AnyObject

Returns self as an AnyObject.
Source§

fn as_any_object(&self) -> &AnyObject

Returns a reference to self as an AnyObject.
Source§

fn as_any_slice(&self) -> &[AnyObject]

Returns self as a reference to a single-element slice.
Source§

fn raw(self) -> usize

Returns the raw object pointer.
Source§

unsafe fn as_unchecked<O: Object>(&self) -> &O

Casts self to O without checking whether it is one.
Source§

unsafe fn into_unchecked<O: Object>(self) -> O

Converts self to O without checking whether it is one.
Source§

fn id(self) -> u64

Returns the object’s identifier.
Source§

fn class(self) -> Class<Self>

Returns the Class for self. Read more
Source§

fn singleton_class(self) -> Class<Self>

Returns the singleton Class of self, creating one if it doesn’t exist already. Read more
Source§

fn mark(self)

Marks self for Ruby to avoid garbage collecting it.
Source§

unsafe fn force_recycle(self)

Forces the garbage collector to free the contents of self. Read more
Source§

fn def_singleton_method<N, F>(self, name: N, f: F) -> Result
where N: Into<SymbolId>, F: MethodFn<Self>,

Defines a method for name on the singleton class of self that calls f when invoked.
Source§

unsafe fn def_singleton_method_unchecked<N, F>(self, name: N, f: F)
where N: Into<SymbolId>, F: MethodFn<Self>,

Defines a method for name on the singleton class of self that calls f when invoked. Read more
Source§

unsafe fn call(self, method: impl Into<SymbolId>) -> AnyObject

Calls method on self and returns its output. Read more
Source§

unsafe fn call_protected(self, method: impl Into<SymbolId>) -> Result<AnyObject>

Calls method on self and returns its output, or an exception if one is raised. Read more
Source§

unsafe fn call_with( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> AnyObject

Calls method on self with args and returns its output. Read more
Source§

unsafe fn call_with_protected( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> Result<AnyObject>

Calls method on self with args and returns its output, or an exception if one is raised. Read more
Source§

unsafe fn call_public(self, method: impl Into<SymbolId>) -> AnyObject

Calls the public method on self and returns its output. Read more
Source§

unsafe fn call_public_protected( self, method: impl Into<SymbolId>, ) -> Result<AnyObject>

Calls the public method on self and returns its output, or an exception if one is raised. Read more
Source§

unsafe fn call_public_with( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> AnyObject

Calls the public method on self with args and returns its output. Read more
Source§

unsafe fn call_public_with_protected( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> Result<AnyObject>

Calls the public method on self with args and returns its output, or an exception if one is raised. Read more
Source§

fn inspect(self) -> String

Returns a printable string representation of self. Read more
Source§

fn to_s(self) -> String

Returns the result of calling the to_s method on self.
Source§

fn is_frozen(self) -> bool

Returns whether modifications can be made to self.
Source§

fn freeze(self)

Freezes self, preventing any further mutations.
Source§

fn is_eql<O: Object>(self, other: &O) -> bool

Returns whether self is equal to other in terms of the eql? method.
Source§

fn get_attr<N: Into<SymbolId>>(self, name: N) -> AnyObject

Returns the value for the attribute of self associated with name.
Source§

unsafe fn eval(self, args: impl EvalArgs) -> AnyObject

Evaluates args in the context of self. Read more
Source§

unsafe fn eval_protected(self, args: impl EvalArgs) -> Result<AnyObject>

Evaluates args in the context of self, returning any raised exceptions. Read more
Source§

impl<O: Object> PartialEq<O> for Module

Source§

fn eq(&self, other: &O) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Module

Source§

impl Eq for Module

Auto Trait Implementations§

§

impl Freeze for Module

§

impl RefUnwindSafe for Module

§

impl !Send for Module

§

impl !Sync for Module

§

impl Unpin for Module

§

impl UnwindSafe for Module

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.