简体   繁体   中英

Getting access to a hash - Ruby

I'm trying to get to data that I found in a binding.pry --- Here is is

[#<Stripe::Card:0x3fc1da530e18 id=card_1A4KjTLcGwfBVD0DjTHzDqsO> JSON: {
  "id": "card_1A4KjTLcGwfBVD0DjTHzDqsO",
  "object": "card",
  "address_city": null,
  "address_country": null,
  "address_line1": null,
  "address_line1_check": null,
  "address_line2": null,
  "address_state": null,
  "address_zip": "42424",
  "address_zip_check": "pass",
  "brand": "Visa",
  "country": "US",
  "customer": "cus_AP91mImLV1GIrS",
  "cvc_check": "pass",
  "dynamic_last4": null,
  "exp_month": 4,
  "exp_year": 2024,
  "fingerprint": "U2Lh3jtN9G5jgtxm",
  "funding": "credit",
  "last4": "4242",
  "metadata": {},
  "name": null,
  "tokenization_method": null
}]

I get all that data when I type this in the console: context.customer.sources.data

I've tried getting the object like this: context.customer.sources.data[:object] but that gives me this error => TypeError: no implicit conversion of Symbol into Integer

How do I get to that data?

Because it's an array. so you should visit like context.customer.sources.data[0][:object] or context.customer.sources.data[0].object

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM