pub struct RModule(/* private fields */);
Expand description
A Value pointer to a RModule struct, Ruby’s internal representation of modules.
See the Module
trait for defining instance methods and nested
classes/modules.
See the Object
trait for defining singlton methods (aka class methods).
See the ReprValue
trait for additional methods available on this type.
See Ruby
for methods to create an RModule
.
Implementations§
source§impl RModule
impl RModule
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(RModule)
if val
is a RModule
, None
otherwise.
§Examples
use magnus::{eval, RModule};
assert!(RModule::from_value(eval("Enumerable").unwrap()).is_some());
assert!(RModule::from_value(eval("String").unwrap()).is_none());
assert!(RModule::from_value(eval("nil").unwrap()).is_none());
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new anonymous module.
§Panics
Panics if called from a non-Ruby thread. See Ruby::module_new
for
the non-panicking version.
§Examples
use magnus::{class, prelude::*, RModule};
let module = RModule::new();
assert!(module.is_kind_of(class::module()));
sourcepub fn define_module_function<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
pub fn define_module_function<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
Define a method in self
’s scope as a ‘module function’. This method
will be visible as a public ‘class’ method on the module and a private
instance method on any object including the module.
§Examples
use magnus::{define_module, function, r_string, rb_assert, RString};
fn greet() -> RString {
r_string!("Hello, world!")
}
let module = define_module("Greeting").unwrap();
module
.define_module_function("greet", function!(greet, 0))
.unwrap();
rb_assert!(r#"Greeting.greet == "Hello, world!""#);
rb_assert!(
r#"
include Greeting
greet == "Hello, world!"
"#,
);
Trait Implementations§
source§impl Module for RModule
impl Module for RModule
source§fn define_class<T>(self, name: T, superclass: RClass) -> Result<RClass, Error>where
T: IntoId,
fn define_class<T>(self, name: T, superclass: RClass) -> Result<RClass, Error>where
T: IntoId,
Define a class in
self
’s scope. Read moresource§fn define_module<T>(self, name: T) -> Result<RModule, Error>where
T: IntoId,
fn define_module<T>(self, name: T) -> Result<RModule, Error>where
T: IntoId,
Define a module in
self
’s scope. Read moresource§fn define_error<T>(
self,
name: T,
superclass: ExceptionClass
) -> Result<ExceptionClass, Error>where
T: IntoId,
fn define_error<T>(
self,
name: T,
superclass: ExceptionClass
) -> Result<ExceptionClass, Error>where
T: IntoId,
Define an exception class in
self
’s scope. Read moresource§fn is_inherited<T>(self, other: T) -> bool
fn is_inherited<T>(self, other: T) -> bool
source§fn ancestors(self) -> RArray
fn ancestors(self) -> RArray
Return the classes and modules
self
inherits, includes, or prepends. Read moresource§fn define_method<T, M>(self, name: T, func: M) -> Result<(), Error>
fn define_method<T, M>(self, name: T, func: M) -> Result<(), Error>
Define a method in
self
’s scope. Read moresource§fn define_private_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
fn define_private_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
Define a private method in
self
’s scope. Read moresource§fn define_protected_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
fn define_protected_method<M>(self, name: &str, func: M) -> Result<(), Error>where
M: Method,
Define a protected method in
self
’s scope. Read moresource§impl Object for RModule
impl Object for RModule
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,
Define a singleton method in
self
’s scope. Read moresource§impl ReprValue for RModule
impl ReprValue for RModule
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 RModule
impl TryConvert for RModule
impl Copy for RModule
Auto Trait Implementations§
impl Freeze for RModule
impl RefUnwindSafe for RModule
impl Send for RModule
impl Sync for RModule
impl Unpin for RModule
impl UnwindSafe for RModule
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