ruby - Does a variable know of the array its in? -


if variable inside array, can find array variable? or variable have no knowledge of data structure it's inside?

just wondering if following possible (the pseudo code v's its_array method):

array = [:a, :b] array.object_id #=> 11709100  array_from_inside = [] array.map |v|     v.its_array.object_id #=> 11709100 11709100     array_from_inside = v.its_array #=> [:a, :b] [:a, :b] end array_from_inside.object_id #=> 11709100 array_from_inside #=> [:a, :b] 

first off, don't put variables in arrays. put objects in arrays, , variables aren't objects in ruby, cannot put them in arrays. in fact, since variables aren't objects in ruby, pretty cannot anything them. ruby object-oriented language, whenever want or something, either calling method on thing or passing thing argument method. can call methods on objects , can pass objects arguments, , variables aren't objects, cannot of that. can 2 things variables: assign them , dereference them.

secondly, no, in general, object not , must not know container put into. more or less negate whole point of containers: can put arbitrary objects them.

plus, its_array return object in no array? or in 2 arrays? or in array in array in array?


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -