Ruby语法错误,意外的tIDENTIFIER,期望输入结束

时间:2015-09-01 09:34:24

标签: ruby syntax-error

我正在研究一个简单的ruby应用程序,只是为了尝试Ruby。现在的想法是创建一些名称树并显示那些,但是我得到以下错误,我不明白为什么 syntax error, unexpected tIDENTIFIER, expecting end-of-input 这是我的代码

class Tree
    attr_accessor :children, :node_name

    def initialize(name, children=[]) 
        @children = children
        @node_name = name
    end

    def visit_all(&block)
        visit &block
        children.each {|c| c.visit_all &block}
    end

    def visit(&block) 
        block.call self
    end 
end

ruby_tree = Tree.new( "Ruby", [Tree.new("Reia"), Tree.new("MacRuby")] )

puts "Visiting a node"

ruby_tree.visit {|node| puts node.node_name} puts

puts "visiting entire tree"

ruby_tree.visit_all {|node| puts node.node_name}

1 个答案:

答案 0 :(得分:0)

这条线让我头疼。看跌期权并不属于所有人!

ruby_tree.visit {|node| puts node.node_name} puts