开发者

Ruby 1.9.1 syntax error

I am currently deploying a rails application to heroku. The application is rails 2.3.3 and for some reason maybe because its a different ruby I am not getting a weird syntax error

HERE IS MY ERROR

Downloading postal codes.
rake aborted!
/app/app/models/postal_code.rb:13: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
      when Integer: first(:conditions => { :code => code })
                   ^
/app/app/models/postal_code.rb:14: syntax error, unexpected keyword_when, expecting keyword_end
      when Hash: first(:conditions => {...
          ^
/app/app/models/postal_code.rb:59: syntax error, unexpected keyword_end, expecting $end

HERE IS MY CODE FILE (postal_code.rb)

11  def self.get(code)
12   case code
13    when Integer: first(:conditions => { :code => code })
14    when Hash: first(:conditions => { :city => code[:city], :state => code[:state] })
15    else raise InternalException.new("Invali开发者_C百科d input.")
16    end
17  end


51    # now set min and max lat and long accordingly
52    area[:min_lat] = latitude - area[:lat_degrees]
53    area[:max_lat] = latitude + area[:lat_degrees]
54    area[:min_lon] = longitude - area[:lon_degrees]
55    area[:max_lon] = longitude + area[:lon_degrees]    
56      
57    area  
58  end

Any ideas what is it thats going wrong


From the 1.9.1 NEWS file:

* Deprecated syntax
      o colon (:) instead of "then" in if/unless or case expression.

So you can't use a colon with a case anymore. You can use then:

case code
  when Integer then first(:conditions => { :code => code })
  when Hash    then first(:conditions => { :city => code[:city], :state => code[:state] })
  else raise InternalException.new("Invalid input.")
end

or newlines:

case code
  when Integer
    first(:conditions => { :code => code })
  when Hash
    first(:conditions => { :city => code[:city], :state => code[:state] })
  else
    raise InternalException.new("Invalid input.")
end


This should work:

def self.get(code)
 case code
  when Integer then first(:conditions => { :code => code })
  when Hash then first(:conditions => { :city => code[:city], :state => code[:state] })
  else raise InternalException.new("Invalid input.")
  end
end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜