Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
String#bitwise_not!
bitwise_not! → self
string.c
View on GitHub ↗
static VALUE
rb_str_bitwise_not_bang(VALUE str)
{
rb_len_t len;
unsigned char *ptr;
rb_str_modify(str);
len = RSTRING_LEN(str);
ptr = (unsigned char *)RSTRING_PTR(str);
str_bitwise_not(ptr, ptr, len);
return str;
}
Replaces each byte in self with its bitwise complement; returns self:
Example
s = "\x00\xAA" s.bitwise_not! # => "\xFF\x55" s # => "\xFF\x55"
The encoding of self is not changed.