jeudi 17 novembre 2016

How can I dynamically access all config parameters starting with 'var' defined in config/applications.rb?

In my config/applications.rb, I have set parameters:

config.var1 = 1
config.var2 = 5
config.varx = 7

I can access them using

Rails.application.config.var1

I am trying to dynamically build a hash of all config parameters with names starting with 'var', so the output would be

{var1: 1, var2: 5, varx: 7}

I have looked at the Rails.application.config.methods, Rails.application.config.instance_variables, Rails.application.config.inspect etc. and they don't return the var1 etc.

How can I dynamically access all config parameters starting with 'var' defined in config/applications.rb?

Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire