轨道提取变量从怪杰返回的hashie
问题描述:
我正在使用名为Desk的宝石从desk.com的API返回数据。当我运行Desk.customers(:custom_external_id => temp.id)
时,它返回一组可爱的数据。轨道提取变量从怪杰返回的hashie
我在寻找id=71095620
的整数71095620。
=> #<Hashie::Rash count=20 page=1 results=[#<Hashie::Rash customer=#<Hashie::Rash addresses=[] custom_external_id="58749" emails=[#<Hashie::Rash email=#<Hashie::Rash created_at="2013-02-13T15:59:26-08:00" email="CENSORED" i
d=33622514 updated_at="2013-02-13T15:59:26-08:00" verified_at=nil>>] first_name="CENSORED" id=68712186 language=nil last_name="CENSORED" phones=[#<Hashie::Rash phone=#<Hashie::Rash created_at="2013-02-13T16:00:45-08:00" id=1301079 phone="CENSORED" updated_at="2013-02-13T16:00:45-08:00">>] twitters=[nil]>>, #<Hashie::Rash customer=#<Hashie::Rash addresses=[] custom_external_id="58749" emails=[] first_name="CENSORED" id=71095620 language=nil last_name="CENSORED" phones=[] twitters=[nil]>>] total=2>
显然存在多个id字段,我不知道哪种方式最好提取该整数。提前致谢!
答
按照Hasie::Rash readme,你也许可以做到这一点
response = Desk.customers(:custom_external_id => temp.id)
response.results[1].customer.id