Skip to content

Instantly share code, notes, and snippets.

@blooberr
Last active October 18, 2016 03:47
Show Gist options
  • Select an option

  • Save blooberr/aeca8fd704ad794bf4ce66038530f230 to your computer and use it in GitHub Desktop.

Select an option

Save blooberr/aeca8fd704ad794bf4ce66038530f230 to your computer and use it in GitHub Desktop.

Revisions

  1. blooberr revised this gist Oct 18, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ruby dup
    Original file line number Diff line number Diff line change
    @@ -2,17 +2,17 @@ a = [5, 3, 2]
    b = a

    # should see [5,3,2]
    puts b
    puts b.inspect

    a[0] = 7

    # should see [7,3,2]
    puts b
    puts b.inspect

    # reset
    a = [5,3,2]
    b = a.dup
    a[0] = 7

    # should see [5,3,2]
    puts b
    puts b.inspect
  2. blooberr created this gist Oct 18, 2016.
    18 changes: 18 additions & 0 deletions ruby dup
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    a = [5, 3, 2]
    b = a

    # should see [5,3,2]
    puts b

    a[0] = 7

    # should see [7,3,2]
    puts b

    # reset
    a = [5,3,2]
    b = a.dup
    a[0] = 7

    # should see [5,3,2]
    puts b