Instance variables

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!!

···

--
Posted via http://www.ruby-forum.com/.

Since you haven't defined an attr_reader for @children, you have to
use the instance variable (@).

···

On Thu, Jun 12, 2008 at 12:06 PM, Justin To <tekmc@hotmail.com> wrote:

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

--
Avdi

Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

# ??? 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

Hi Kevin :slight_smile:

Good catch. I think I missed the point of the OP's question.

···

On Thu, Jun 12, 2008 at 1:00 PM, Kevin Compton <klcompt@gmail.com> wrote:

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 '@'

--
Avdi

Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

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

Thanks!

···

--
Posted via http://www.ruby-forum.com/.

No the parser identifies @children as an instance variable.
R

···

On Thu, Jun 12, 2008 at 7:32 PM, Justin To <tekmc@hotmail.com> wrote:

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