Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: no implicit conversion of Symbol into Integer while reading YAML in Ruby

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?

like image 757
Severin Avatar asked Aug 04 '26 22:08

Severin


1 Answers

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']

like image 187
vee Avatar answered Aug 06 '26 13:08

vee