Instance variables

J

Justin To

class Trie
attr_reader :value, :parent, :child_node
def initialize(value=nil, parent=nil)
@value = value
@children = {}
@parent = parent
@child_node = @children # ??? HERE
end
end

# ??? HERE: Does it matter if I do @child_node = children (without the @
for children)? What's the difference with using the @ and not?

Thank you!!
 
K

Kevin Compton

[Note: parts of this message were removed to make it a legal post.]
# ??? HERE: Does it matter if I do @child_node = children (without the @
for children)? What's the difference with using the @ and not?
It depends on your intent with the variable children. If it is just a
temporary variable that you want to use while generating the @child_node
value then it is fine not to have the '@'

Kevin
 
J

Justin To

Great, thanks. So what if I DID specify attr_reader :children, but still
did @child_node = @children. Would that have any adverse effects?

Thanks!
 
R

Robert Dober

Great, thanks. So what if I DID specify attr_reader :children, but still
did @child_node = @children. Would that have any adverse effects?
No the parser identifies @children as an instance variable.
R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top