Check if property exists in object

I spent a lot of time trying to figure this out myself with the help of other questions, but couldn't, so I really need to ask this again

I have the following object in ruby

(...)
  :follow_request_sent: 
  :notifications:  
:coordinates: 
:place: 
:contributors: 
:favorite_count: 0
:entities:
  :hashtags:
  - :text: 
    :indices:
(...)

      

This object is the X . I want to check if x.place exists . I've tried EVERYTHING. any,?, include ?, with [hash] defined by ?, (...), but it ALWAYS throws an "undefined method" error when trying to access a property, whether it exists or not. It NEVER works and I don't understand why. This is the twitter API by the way. Does anyone imagine why? Please do not point me to the other answers, because basically they all failed.

+3


source to share


1 answer


If you want to see if there is a method like this:

x.respond_to?(:place)

      



If you want to see if there is an instance variable:

x.instance_variable_defined?(:@place)

      

+6


source







All Articles