pub struct RRegexp(/* private fields */);
Expand description
Implementations§
source§impl RRegexp
impl RRegexp
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(RRegexp)
if val
is a RRegexp
, None
otherwise.
§Examples
use magnus::{eval, RRegexp};
assert!(RRegexp::from_value(eval("/f(.)o/").unwrap()).is_some());
assert!(RRegexp::from_value(eval(r#""f*""#).unwrap()).is_none());
sourcepub fn new(pattern: &str, opts: Opts) -> Result<Self, Error>
pub fn new(pattern: &str, opts: Opts) -> Result<Self, Error>
Create a new Regexp
from the Rust string pattern
.
The encoding of the Ruby regexp will be UTF-8.
§Panics
Panics if called from a non-Ruby thread. See Ruby::reg_new
for the
non-panicking version.
§Examples
use magnus::{r_regexp::Opts, rb_assert, RRegexp};
let regexp = RRegexp::new("foo", Opts::new().ignorecase()).unwrap();
rb_assert!(r#"regexp == /foo/i"#, regexp);
sourcepub fn new_str(pattern: RString, opts: Opts) -> Result<Self, Error>
pub fn new_str(pattern: RString, opts: Opts) -> Result<Self, Error>
Create a new Regexp
from the Ruby string pattern
.
§Examples
use magnus::{r_regexp::Opts, rb_assert, RRegexp, RString};
let regexp = RRegexp::new_str(RString::new("foo"), Opts::new().ignorecase()).unwrap();
rb_assert!(r#"regexp == /foo/i"#, regexp);
sourcepub fn reg_match<T>(self, s: T) -> Result<Option<usize>, Error>where
T: IntoRString,
pub fn reg_match<T>(self, s: T) -> Result<Option<usize>, Error>where
T: IntoRString,
Returns the index (in characters) of the first match in s
.
§Examples
use magnus::RRegexp;
let regexp = RRegexp::new("x", Default::default()).unwrap();
assert_eq!(regexp.reg_match("text").unwrap(), Some(2));
assert_eq!(regexp.reg_match("test").unwrap(), None);
sourcepub fn options(self) -> Opts
pub fn options(self) -> Opts
Returns the options set for self
.
§Examples
use magnus::{eval, RRegexp};
let regexp: RRegexp = eval("/x/i").unwrap();
assert!(regexp.options().is_ignorecase());
assert!(!regexp.options().is_multiline());
let regexp: RRegexp = eval("/x/m").unwrap();
assert!(!regexp.options().is_ignorecase());
assert!(regexp.options().is_multiline());
Trait Implementations§
source§impl EncodingCapable for RRegexp
impl EncodingCapable for RRegexp
source§impl ReprValue for RRegexp
impl ReprValue for RRegexp
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 RRegexp
impl TryConvert for RRegexp
impl Copy for RRegexp
Auto Trait Implementations§
impl Freeze for RRegexp
impl RefUnwindSafe for RRegexp
impl Send for RRegexp
impl Sync for RRegexp
impl Unpin for RRegexp
impl UnwindSafe for RRegexp
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