语法错误,意外IDENTIFIER,期待keyword_end

时间:2013-03-25 05:13:33

标签: ruby-on-rails ruby

我已多次检查此代码,但我找不到此语法错误的原因。

syntax error, unexpected tIDENTIFIER, expecting keyword_end   

这是代码:

# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require '00 hello/version'

Gem::Specification.new do |spec|
  spec.name          = "00 hello"
  spec.version       = 00 hello_VERSION
  spec.authors       = ["John Kirtley"]
  spec.email         = ["KirtleyJ16@gmail.com"]
  spec.description   = %q{TODO: Write a gem description}
  spec.summary       = %q{TODO: Write a gem summary}
  spec.homepage      = ""
  spec.license       = "MIT"

  spec.files         = `git ls-files`.split($/)
  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
  spec.require_paths = ["lib"]

  spec.add_development_dependency "bundler", "~> 1.3"
  spec.add_development_dependency "rake"
end

这是修改后的代码:

# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require = 00hello_version



Gem::Specification.new do |spec|
  spec.name          = "00hello"
  spec.version       = "00hello:VERSION"
  spec.authors       = ["John Kirtley"]
  spec.email         = ["KirtleyJ16@gmail.com"]
  spec.description   = %q{TODO: Write a gem description}
  spec.summary       = %q{TODO: Write a gem summary}
  spec.homepage      = ""
  spec.license       = "MIT"

  spec.files         = `git ls-files`.split($/)
  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) })
  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
  spec.require_paths = ["lib"]

  spec.add_development_dependency "bundler", "~> 1.3"
  spec.add_development_dependency "rake"
end

我稍微更改了代码,现在我得到的错误是:

There was a SyntaxError while loading hello.gemspec:
/Users/John/$/hello.gemspec:4: syntax error, unexpected tIDENTIFIER, expecting end-of-input
/Users/John/$/Rakefile:1:in `<top (required)>'
/Users/John/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
/Users/John/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
(See full trace by running task with --trace)

3 个答案:

答案 0 :(得分:1)

你可以注释掉直到找到它......

00 hello_Version看起来很狡猾。

答案 1 :(得分:0)

您需要引用spec.version部分。

spec.version = '00 hello_VERSION'

答案 2 :(得分:0)

spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }

缺少一个结束的paren