Module: Unsafe
- Defined in:
- lib/unsafe.rb,
lib/unsafe/version.rb,
ext/unsafe/unsafe.c
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
- .array_aref(array, idx) ⇒ Object
- .array_aset(array, idx, value) ⇒ Object
- .string_aref(*args) ⇒ Object
Class Method Details
.array_aref(array, idx) ⇒ Object
5 6 7 |
# File 'ext/unsafe/unsafe.c', line 5 VALUE array_aref(VALUE self, VALUE array, VALUE idx) { return RARRAY_PTR(array)[FIX2LONG(idx)]; } |
.array_aset(array, idx, value) ⇒ Object
9 10 11 |
# File 'ext/unsafe/unsafe.c', line 9 VALUE array_aset(VALUE self, VALUE array, VALUE idx, VALUE value) { return RARRAY_PTR(array)[FIX2LONG(idx)] = value; } |
.string_aref(*args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'ext/unsafe/unsafe.c', line 13 VALUE string_aref(int argc, VALUE *argv, VALUE self) { long idx, len = 1; if (argc == 3) { len = NUM2INT(argv[2]); } else { rb_check_arity(argc, 2, 3); } VALUE string = argv[0]; idx = NUM2INT(argv[1]); return rb_str_new(RSTRING_PTR(string) + idx, len); } |