I have the following defined in a module in my Rails application:
module Selecting
module Execution
class ExecuteSpecific
def self.perform!
input = Data::FetchData.new.perform_action(param1, params2)
To make the code more general I want to remove the specific methodcall from the function and mode it to a YAML file as such:
:Newname:
- example: 'Data::FetchData.new.perform_action(param1, params2)'
and refactor the above to ("name" should be passed as a symbol):
module Selecting
module Execution
class ExecuteSpecific
def self.perform! name
new = YAML.load_file('path/to/file.yml')[name]
input = new[:example]
This return a
TypeError: no implicit conversion of Symbol into Integer
How can that be fixed?
That error is saying you are using a symbol where it expects an integer. The only place you are doing that is where you call new[:example]. Yaml.load_file returns array of strings and not symbols, so if you access your yaml loaded document using string index instead of symbol that should solve the problem.
Eg. input = new['example']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With