A
A
Alexander Grishin2016-02-08 19:14:15
ruby
Alexander Grishin, 2016-02-08 19:14:15

Pointers in ruby ​​- how does it work?

class Test1
 def init
  array = [VERY, BIG, ARRAY]
  Test2.new(array).reread
 end
end
class Test2
 def initialize(array)
  @array = array # ????
 end

How to operate on large arrays, for example read from the database using pointers in RUBY ?
Or RUBY itself operates with pointers to objects in memory and nothing needs to be done, i.e. Is my version of an instance variable quite suitable?
I know there is an option.
class Test2
 def initialize(options)
  options[:array]
 end
end

But in this case, how can we move our array out of the scope of the initialization method?
If you do this, @options = options[:array]then this is reinitialization again, and as I understand it, the array will be overwritten into a new variable object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2016-02-08
@beerdy

Ruby doesn't have pointers. All variables are references to objects in shared memory. Call the object_id function on objects to see what a particular variable refers to

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question