1 / 10

Object Creation CAVEAT EMPTOR!!!

Object Creation CAVEAT EMPTOR!!!. Addendum to unit 8 Gideon Frieder 2012. irb(main):001:0> a = 5 => 5. irb(main):002:0> a.object_id => 11. irb(main):003:0> b = 6 => 6. irb(main):004:0> b.object_id => 13. irb(main):005:0> b = a => 5.

Download Presentation

Object Creation CAVEAT EMPTOR!!!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object CreationCAVEAT EMPTOR!!! Addendum to unit 8 Gideon Frieder 2012

  2. irb(main):001:0> a = 5 => 5 irb(main):002:0> a.object_id => 11 irb(main):003:0> b = 6 => 6 irb(main):004:0> b.object_id => 13 irb(main):005:0> b = a => 5 irb(main):006:0> b.object_id => 11

  3. irb(main):001:0> a = [1,2,3] => [1, 2, 3] irb(main):002:0> a.object_id =>15627456 irb(main):003:0> b = a => [1, 2, 3] irb(main):004:0> b.object_id =>15627456 irb(main):005:0> a => [1, 2, 3] irb(main):006:0> b => [1, 2, 3]

  4. Now see this……. irb(main):007:0> a[1] = 99 => 99 PART of a is changed irb(main):008:0> a => [1, 99, 3] What about b? irb(main):009:0> b => [1, 99, 3]

  5. irb(main):001:0> a = [1,2,3] => [1, 2, 3] irb(main):002:0> b = Array.new => [] irb(main):003:0> a.object_id =>16770948 irb(main):004:0> b.object_id =>16263168 irb(main):005:0> b = a => [1, 2, 3] irb(main):006:0> b.object_id =>16770948 irb(main):007:0> a[1] = 99 => 99 irb(main):008:0> a => [1, 99, 3] irb(main):009:0> b => [1, 99, 3]

  6. irb(main):001:0> a = [1,2,3] => [1, 2, 3] irb(main):002:0> b = Array.new(a) =>[1, 2, 3] irb(main):003:0> a.object_id => 16007148 irb(main):004:0> b.object_id => 16833036 irb(main):005:0> a[1] = 99 => 99 irb(main):006:0> a => [1, 99, 3] irb(main):006:0> b => [1, 2, 3]

  7. New value assignment creates new object Assigning of an existing object name to another name does NOT create a new object, It creates a duplicate name for the same object

More Related