Module: Xorcist
- Defined in:
- lib/xorcist.rb,
lib/xorcist/version.rb,
lib/xorcist/refinements.rb,
lib/xorcist/string_methods.rb,
ext/xorcist/xorcist.c
Defined Under Namespace
Modules: Refinements, StringMethods
Constant Summary
collapse
- VERSION =
'1.1.0'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.xor(x, y) ⇒ Object
12
13
14
|
# File 'lib/xorcist.rb', line 12
def xor(x, y)
xor!(x.dup, y)
end
|
.xor!(x, y) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'ext/xorcist/xorcist.c', line 9
VALUE xor_in_place(VALUE self, VALUE x, VALUE y) {
const char *src = 0;
char *dest = 0;
size_t len;
size_t y_len;
if (TYPE(x) != T_STRING) {
rb_raise( rb_eTypeError, "first argument must be a String" );
return Qnil;
}
if (TYPE(y) != T_STRING) {
rb_raise( rb_eTypeError, "second argument must be a String" );
return Qnil;
}
rb_str_modify(x);
dest = RSTRING_PTR(x);
len = RSTRING_LEN(x);
src = RSTRING_PTR(y);
y_len = RSTRING_LEN(y);
if (y_len < len) {
len = y_len;
}
for (; len--; ++dest, ++src) {
*dest ^= *src;
}
return x;
}
|
Instance Method Details
#_xor! ⇒ Object
19
|
# File 'lib/xorcist.rb', line 19
alias_method :_xor!, :xor!
|