Project

General

Profile

Feature #6373 » itself.diff

rafaelfranca (Rafael França), 08/01/2014 06:22 PM

View differences:

include/ruby/intern.h
573 573
VALUE rb_obj_alloc(VALUE);
574 574
VALUE rb_obj_clone(VALUE);
575 575
VALUE rb_obj_dup(VALUE);
576
VALUE rb_obj_itself(VALUE);
576 577
VALUE rb_obj_init_copy(VALUE,VALUE);
577 578
VALUE rb_obj_taint(VALUE);
578 579
VALUE rb_obj_tainted(VALUE);
object.c
402 402
    return dup;
403 403
}
404 404

  
405
/*
406
 *  call-seq:
407
 *     obj.itself -> an_object
408
 *
409
 *  Returns <i>obj</i>.
410
 *
411
 *	string = 'my string' #=> "my string"
412
 *	string.itself.object_id == string.object_id #=> true
413
 *
414
 */
415
VALUE
416
rb_obj_itself(VALUE obj)
417
{
418
    return obj;
419
}
420

  
405 421
/* :nodoc: */
406 422
VALUE
407 423
rb_obj_init_copy(VALUE obj, VALUE orig)
......
3302 3318
    rb_define_method(rb_mKernel, "singleton_class", rb_obj_singleton_class, 0);
3303 3319
    rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
3304 3320
    rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
3321
    rb_define_method(rb_mKernel, "itself", rb_obj_itself, 0);
3305 3322
    rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
3306 3323
    rb_define_method(rb_mKernel, "initialize_dup", rb_obj_init_dup_clone, 1);
3307 3324
    rb_define_method(rb_mKernel, "initialize_clone", rb_obj_init_dup_clone, 1);
test/ruby/test_object.rb
12 12
    $VERBOSE = @verbose
13 13
  end
14 14

  
15
  def test_itself
16
    object = Object.new
17
    assert_equal object, object.itself
18
    assert_equal object.object_id, object.itself.object_id
19
  end
20

  
15 21
  def test_dup
16 22
    assert_raise(TypeError) { 1.dup }
17 23
    assert_raise(TypeError) { true.dup }