Hello I have the following object
object = [#<ShopifyAPI::DiscountCode:0x000000000e1c78a8 @attributes={"code"=>"Disc2", "amount"=>"1.00", "type"=>"percentage"}, @prefix_options={}, @persisted=true>]
How can I properly access the “code” name of that object?
I have tried object[:code] and object.code but it appears I am overlooking something.
3
Answers
First, object is array:
Second, this is instance variable:
Last, gets values by keys:
object is an array of ShopifyAPI::DiscountCode.
The best way to access it is
If u want code of all the objects available in the array, you could get the array of values by
Given that this is an
Array
ofShopifyAPI::DiscountCode
s (which inherit fromActiveResource::Base
)You can call the
code
method on them. eg: