even though rails.application.config.trackable_models
returns full array, defined?(rails.application.config.trackable_models)
returns nil.
rails.application.config.trackable_models # => ["newsitem", "contentpage", "event"] defined?(rails.application.config.trackable_models): # => nil
setting local variable in same way fine:
foo = ["x"] defined?(foo) # => local-variable
what proper way check existence of config variable if not "defined?"?
if want check method defined in literal sense, use respond_to
rails.applications.config.respond_to?(:trackable_models)
if want check if method returns other nil
, have options:
tm = rails.applications.config.trackable_models tm.nil? tm.presence || 'default value' tm.present? tm.blank?
Comments
Post a Comment