【问题标题】:Ruby syntax error, unexpected tIDENTIFIER, expecting end-of-inputRuby 语法错误,意外的 tIDENTIFIER,期待输入结束
【发布时间】:2015-11-26 11:39:43
【问题描述】:

我正在开发一个简单的 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}

【问题讨论】:

  • 行数(整个错误消息)在这里会很有帮助。

标签: ruby syntax-error


【解决方案1】:

这句话让我很头疼。 put不属于所有!

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

【讨论】:

  • 这如何提供我的答案没有提供的任何信息?
猜你喜欢
  • 2014-09-16
  • 2014-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-18
  • 1970-01-01
相关资源
最近更新 更多