【问题标题】:Complex if condition with parameters [closed]带有参数的复杂条件[关闭]
【发布时间】:2013-01-24 10:59:41
【问题描述】:
if @near.nil?
  loc, @near, found = get_user_geolocation
else
  loc = GeoKit::Geocoders::GoogleGeocoder.geocode(@near)
  found = loc.success
  @near = loc.full_address
end

在第一个 if 部分,发生了什么?我可能不擅长语法,但这让我很好奇。 提前致谢。

【问题讨论】:

  • @near.nil? 让您感到困惑,还是loc, @near, found = get_user_geolocation
  • 这段代码究竟遇到了什么问题?
  • loc, @near, found = get_user_geolocation

标签: ruby-on-rails ruby ruby-on-rails-3 google-geocoder


【解决方案1】:

Multiple Assignment

> a,b,c = [10,20,30] # or a,b,c = 10,20,30
> a => 10 
> b => 20 
> c => 30 

【讨论】:

    【解决方案2】:

    get_user_geolocation 方法返回三个值:loc@nearfound

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      相关资源
      最近更新 更多