怎么读!ruby / object?

时间:2014-06-19 19:00:20

标签: ruby-on-rails ruby

我得到Tinypass Gem的回复:

-- !ruby/object:Tinypass::Gateway::PagedList 
list: 
- !ruby/object:Tinypass::Gateway::AccessDetails 
  table: 
    :created: 1403203101
    :uid: MHC3D8N6QS
    :tags: []

    :resource_name: Dashboard content
    :rid: dashboard
    :recur: false
    :expires: 1403807901
    :aid: OQhD8dX7RX
    :amount_usd: 0.5
    :currency: USD
    :amount: 0.5
    :id: LlQpHb1XvzUP
    :user_email: visa@gmail.com
- !ruby/object:Tinypass::Gateway::AccessDetails 
  table: 
    :created: 1403082355
    :uid: H5fRXBjZ3A
    :tags: []

    :resource_name: Dashboard content
    :rid: dashboard
    :user_ref: badashah29
    :recur: false
    :expires: 1403687155
    :aid: OQhD8dX7RX
    :amount_usd: 0.99
    :currency: USD
    :amount: 0.99
    :id: ORvo1LjBs4Hk
    :user_email: badashah265@mailcatch.com

任何人都可以建议我如何从此响应中读取user_ref,user_email参数。

由于

1 个答案:

答案 0 :(得分:0)

这样的事情应该有效:

require 'yaml'

# parse the yaml from the response
list = YAML.load(response)

# do something with the list
list.each {|access_detail| p access_detail }