Ruby, No Implicit Conversion of Symbol into Integer

TypeError: no implicit conversion of Symbol into Integer

Your item variable holds Array instance (in [hash_key, hash_value] format), so it doesn't expect Symbol in [] method.

This is how you could do it using Hash#each:

def format(hash)
output = Hash.new
hash.each do |key, value|
output[key] = cleanup(value)
end
output
end

or, without this:

def format(hash)
output = hash.dup
output[:company_name] = cleanup(output[:company_name])
output[:street] = cleanup(output[:street])
output
end

no implicit conversion of Symbol into Integer rails 5.2.2.1

no implicit conversion of Symbol into Integer (TypeError)

This is error is raised in this case because you're trying to access to the elements in an array as it'd be a hash. Ruby tries to convert the symbol you're passing as parameter to the [] method, because the receiver is an array, and arrays can be accessed to their elements by their index.

In short, you have an array of hashes, if you need the id from one of them, filter the elements until you get it and there you can use ['id']:

[{ "id"=>2, "name"=>"Cafe", "service_code"=>0 },
{ "id"=>3, "name"=>"restaurant", "service_code"=>0 }][0]['id']
# 2

No implicit conversion of Symbol into Integer only happening sometimes

Hi guys I appreciate your answers.

The real cause was because our jenkins agent wasn't deploying the code to all our instances.

Ruby on rails array - no implicit conversion of symbol into integer

tl;dr

use @movieList["movies"].each

explanation

The issue here, is that you act as though your @movieList is ann array, when it is actually a hash (assuming @movieList is the JSON you showed).

each works on both arrays and hashes. However, when you use it on a hash, the block is passed |key, val|. Also, assigning block variables is optional. So, when you say @movieList.each do |item|, item is actually the top level key of the hash ("movies").

Strings such as "movies" respond to [] indexing with numbers. That's why you get the error no implicit conversion of symbol into integer ... because you pass a symbol to String#[] and it expects an integer.

Another way to write this code, that is more idiomatic, would be like so:

@movies = @movieList["movies"].map do |movie|
{
column1: movie["title"],
column2: movie["year"],
column3: movie["format"]
}
end

no implicit conversion of Symbol into Integer: Octokit

your "path" of accessing the content (comment[:user][:login]) does absolutely not match your datastructure.

  1. its users not user
  2. the root object is a hash, not an array
  3. you have a nested array, which you are not iterating over

maybe you want this

client.pull_request_reviewer("healtheintent/hcc_reference_service", 129)[:users].each do |user|
username = user[:login]

the reason you are getting a "no implicit conversion of Symbol into Integer" is, because you are using the [] notation on an array, but giving it a symbol as key/index (because you wrongly assumed to be a hash)



Related Topics



Leave a reply



Submit