我想将res
放入array[google, Rue Abdallaye, null, Trarza, null, 18.0951362, -15.9806735, MR, true]
。我怎么做?感谢。
>> puts res
Provider: google
Street: Rue Abdallaye
City:
State: Trarza
Zip:
Latitude: 18.0951362
Longitude: -15.9806735
Country: MR
Success: true
=> nil
>> res.kind_of?(Array)
=> false
>> res.inspect
=> "#<Geokit::GeoLoc:0x1021f10c8 @city=nil, @province=\"Nouakchott\", @country=\"Mauritania\", @street_address=\"Rue Abdallaye\", @suggested_bounds=#<Geokit::Bounds:0x101f9f8d8 @ne=#<Geokit::LatLng:0x101f9f748 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101f9f810 @lng=-15.9820212, @lat=18.0937799>>, @country_code=\"MR\", @state=\"Trarza\", @all=[#<Geokit::GeoLoc:0x1021f10c8 ...>, #<Geokit::GeoLoc:0x101f9f5e0 @city=\"Nouakchott\", @province=nil, @country=\"Mauritania\", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x101d624a8 @ne=#<Geokit::LatLng:0x101d62458 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101d62480 @lng=-15.9820212, @lat=18.0937799>>, @country_code=\"MR\", @state=\"Nouakchott\", @all=[#<Geokit::GeoLoc:0x101f9f5e0 ...>], @accuracy=4, @lng=-15.9993672, @full_address=\"Tevragh Zeina, Nouakchott, Mauritania\", @provider=\"google\", @precision=\"city\", @zip=nil, @lat=18.110344, @success=true>, #<Geokit::GeoLoc:0x101d62048 @city=\"Nouakchott\", @province=nil, @country=\"Mauritania\", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x101506f70 @ne=#<Geokit::LatLng:0x101506ef8 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101506f20 @lng=-15.9820212, @lat=18.0937799>>, @country_code=\"MR\", @state=\"Nouakchott\", @all=[#<Geokit::GeoLoc:0x101d62048 ...>], @accuracy=4, @lng=-15.97842, @full_address=\"Nouakchott, Mauritania\", @provider=\"google\", @precision=\"city\", @zip=nil, @lat=18.084061, @success=true>, #<Geokit::GeoLoc:0x1015069d0 @city=nil, @province=\"نواكشوط\", @country=\"Mauritania\", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x101274e10 @ne=#<Geokit::LatLng:0x101274c58 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x101274de8 @lng=-15.9820212, @lat=18.0937799>>, @country_code=\"MR\", @state=\"ولاية الترارزة\", @all=[#<Geokit::GeoLoc:0x1015069d0 ...>], @accuracy=3, @lng=-15.92299, @full_address=\"Nouakchott, Mauritania\", @provider=\"google\", @precision=\"state\", @zip=nil, @lat=18.1801386, @success=true>, #<Geokit::GeoLoc:0x101274af0 @city=nil, @province=nil, @country=\"Mauritania\", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x1005b4658 @ne=#<Geokit::LatLng:0x1005b4608 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x1005b4630 @lng=-15.9820212, @lat=18.0937799>>, @country_code=\"MR\", @state=\"Nouakchott\", @all=[#<Geokit::GeoLoc:0x101274af0 ...>], @accuracy=2, @lng=-15.92299, @full_address=\"Nouakchott, Mauritania\", @provider=\"google\", @precision=\"state\", @zip=nil, @lat=18.1801386, @success=true>, #<Geokit::GeoLoc:0x1005b41d0 @city=nil, @province=nil, @country=\"Mauritania\", @street_address=nil, @suggested_bounds=#<Geokit::Bounds:0x10349e040 @ne=#<Geokit::LatLng:0x10349dff0 @lng=-15.9793232, @lat=18.0964779>, @sw=#<Geokit::LatLng:0x10349e018 @lng=-15.9820212, @lat=18.0937799>>, @country_code=\"MR\", @state=nil, @all=[#<Geokit::GeoLoc:0x1005b41d0 ...>], @accuracy=1, @lng=-10.940835, @full_address=\"Mauritania\", @provider=\"google\", @precision=\"country\", @zip=nil, @lat=21.00789, @success=true>], @accuracy=6, @lng=-15.9806735, @full_address=\"Rue Abdallaye, Nouakchott, Mauritania\", @provider=\"google\", @precision=\"zip+4\", @zip=nil, @lat=18.0951362, @success=true>"
答案 0 :(得分:3)
请参阅http://geokit.rubyforge.org/api/geokit-gem/Geokit/GeoLoc.html
ary = [res.provider, res.street_name, res.city, res.state, res.zip, res.lng, res.lat, res.country_code, res.success]
答案 1 :(得分:2)
您可以使用res.to_hash
从Geokit :: GeoLoc对象轻松获取哈希值,并使用res.to_hash.values
获取数组。
如果您使用的是Ruby 1.9,则会保留散列键顺序,否则您应该在将值放入数组之前自行对散列进行排序。
贝斯茨,
理查德