Module: FastMethodSource::MethodExtensions
- Included in:
- Method
- Defined in:
- ext/fast_method_source/fast_method_source.c
Instance Method Summary collapse
Instance Method Details
#comment ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/fast_method_source/fast_method_source.c', line 395
static VALUE
mMethodExtensions_comment(VALUE self)
{
VALUE source_location = rb_funcall(self, rb_intern("source_location"), 0);
VALUE name = rb_funcall(self, rb_intern("name"), 0);
check_if_nil(source_location, name);
VALUE rb_filename = RARRAY_AREF(source_location, 0);
VALUE rb_method_location = RARRAY_AREF(source_location, 1);
check_if_nil(rb_filename, name);
check_if_nil(rb_method_location, name);
const char *filename = RSTRING_PTR(rb_filename);
const unsigned method_location = FIX2INT(rb_method_location);
char **filebuf = allocate_memory_for_file();
const unsigned relevant_lines_n = read_lines_before(method_location,
filename, &filebuf);
VALUE comment = find_comment(&filebuf, method_location, relevant_lines_n);
check_if_nil(comment, name);
free_memory_for_file(&filebuf, relevant_lines_n);
return comment;
}
|
#source ⇒ Object
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'ext/fast_method_source/fast_method_source.c', line 367
static VALUE
mMethodExtensions_source(VALUE self)
{
VALUE source_location = rb_funcall(self, rb_intern("source_location"), 0);
VALUE name = rb_funcall(self, rb_intern("name"), 0);
check_if_nil(source_location, name);
VALUE rb_filename = RARRAY_AREF(source_location, 0);
VALUE rb_method_location = RARRAY_AREF(source_location, 1);
check_if_nil(rb_filename, name);
check_if_nil(rb_method_location, name);
const char *filename = RSTRING_PTR(rb_filename);
const unsigned method_location = FIX2INT(rb_method_location);
char **filebuf = allocate_memory_for_file();
const unsigned relevant_lines_n = read_lines_after(method_location,
filename, &filebuf);
VALUE source = find_source(&filebuf, relevant_lines_n);
check_if_nil(source, name);
free_memory_for_file(&filebuf, relevant_lines_n);
return source;
}
|