Skip to content

Instantly share code, notes, and snippets.

@falonofthetower
Last active December 23, 2015 05:11
Show Gist options
  • Save falonofthetower/8570c03e382ed369e37d to your computer and use it in GitHub Desktop.
Save falonofthetower/8570c03e382ed369e37d to your computer and use it in GitHub Desktop.
def spacer
puts "------------------------------------------------------------------------------------"
end
def blank
puts ""
end
puts "the string method"
blank
str = 'hello'
puts "string to begin is: #{str}"
puts "string object id is: #{str.object_id}"
blank
def this_no_change(string)
puts "string object id inside is: #{string.object_id}"
string += ' world'
blank
puts "string inside becomes #{string}"
puts "string object id inside after is: #{string.object_id}"
blank
end
this_no_change(str)
puts "string object id after is: #{str.object_id}"
puts "string after is #{str}"
spacer
puts "the array +="
array = ['hello']
puts "array before is #{array}"
puts "array object id is: #{array.object_id}"
puts "array element object id is: #{array[0].object_id}"
blank
def no_change_here(ary)
puts "array object id inside is: #{ary.object_id}"
puts "array element object id inside is: #{ary[0].object_id}"
blank
ary += ['world']
puts "array object id inside after is: #{ary.object_id}"
puts "array element object id inside after is: #{ary[0].object_id}"
puts "array inside becomes #{ary}"
blank
end
no_change_here(array)
puts "array afterwards is #{array}"
puts "array object id outside after is: #{array.object_id}"
puts "array element object id outside after is: #{array[0].object_id}"
spacer
puts "your method ary[0] = ary[0] + ' world'"
array = ['hello']
puts "array before is #{array}"
puts "array object id is: #{array.object_id}"
puts "array element object id is: #{array[0].object_id}"
blank
def your_method(ary)
puts "array object id inside is: #{ary.object_id}"
puts "array element object id inside is: #{ary[0].object_id}"
blank
ary[0] = ary[0] + ' world'
puts "array object id inside after is: #{ary.object_id}"
puts "array element object id inside after is: #{ary[0].object_id}"
puts "array inside becomes #{ary}"
blank
end
your_method(array)
puts "array afterwards is #{array}"
puts "array object id outside after is: #{array.object_id}"
puts "array element object id outside after is: #{array[0].object_id}"
spacer
def why_does_this(ary)
puts "array object id inside is: #{ary.object_id}"
puts "array element object id inside is: #{ary[0].object_id}"
blank
ary[0] += ' world'
puts "array inside is #{ary}"
puts "array object id inside after is: #{ary.object_id}"
puts "array element object id inside after is: #{ary[0].object_id}"
puts "array inside becomes #{ary}"
blank
end
puts "array before is #{array}"
puts "array object id is: #{array.object_id}"
puts "array element object id is: #{array[0].object_id}"
blank
why_does_this(array)
puts "array afterwards is still...wait what?? #{array}"
puts "array object id outside after is: #{array.object_id}"
puts "array element object id outside after is now!!!: #{array[0].object_id}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment