Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Some
- property s : String, ai : Array(Int32)
- def initialize(@s : String, *some_ints)
- @ai = [] of Int32
- some_ints.each { |e|
- if e.is_a?(Int32)
- @ai << e
- end
- }
- end
- def s_addr
- @s.to_unsafe.address
- end
- def ai_dump
- p @ai
- end
- end
- obj = Some.new("kis-kis", 1, 2, 3)
- copy_of_s = obj.s
- ps = pointerof(copy_of_s)
- puts %(Address in memory of "copied" s: #{copy_of_s.to_unsafe.address})
- puts %(Address in memory of instance variable stored inside object: #{obj.s_addr})
- puts %("copied" s and instance variable is ) + (copy_of_s.to_unsafe.address == obj.s_addr ? "absolutely" : "not") + " the same"
- l = obj.ai
- puts %(Array inside object before change to its "copy")
- obj.ai_dump
- l[0] = 7
- puts %(Array inside object after change to its "copy")
- obj.ai_dump
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement