开发者

Ruby method list: "unexpected kDEF, expecting $end"

I feel pretty dumb having to ask this, but it's had me stumped way too long. Attempting to run the following, I get

finance.rb:1: syntax error, unexpected kDEF, expecting $end

def get_sign(input)
 return "+" if input.include? "+"
 return "-" if input.include? "-"
end

def get_account_name(input)
 if input.split[0] == "new"
  return input.split.reject{|x| x == "new" or x == "account"}[0]
 else
  return input.split[0]
 end
end

If I wrap them in a class, it just expects <, \n, or ; instead of $end.

Ruby 1.8.7 and 1.9 (via Macruby) give the same error. Removing the second method seems to get it 开发者_JAVA技巧working. Someone, please enlighten me; this seems like a really fundamental misunderstanding of something on my part.


I don't get this error if I copy/paste your contents from this question into a new file. If you do so (copy/paste from this web page into a new file and save that) do you still get the error? If not, perhaps you have some garbage whitespace in your file?

Added as answer because another user may find this question with a similar problem and not read through all the comments to find the solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜