From 8470be4b27287a53d53c282267fa570418e09aec Mon Sep 17 00:00:00 2001 From: pakrym-stripe <99349468+pakrym-stripe@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:32:51 -0800 Subject: [PATCH] Update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index f96c75a8e..825b7bebf 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,24 @@ Keep in mind that there are different method signatures depending on the action: `retrieve(id, opts)`. In addition, it will accept a Hash for the `id` param but will extract the `id` key out and use the others as options. +### Accessing resource properties + +Both indexer and accessors can be used to retrieve values of resource properties. + +```ruby +customer = Stripe::Customer.retrieve('cus_123456789') +puts customer['id'] +puts customer.id +``` + +NOTE: If the resource property is not defined, the accessors will raise an exception, while the indexer will return `nil`. + +```ruby +customer = Stripe::Customer.retrieve('cus_123456789') +puts customer['unknown'] # nil +puts customer.unknown # raises NoMethodError +``` + ### Accessing a response object Get access to response objects by initializing a client and using its `request`