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.
- its
users
notuser
- the root object is a hash, not an array
- 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
Ruby Check Whether Program Is Currently Being Closed
Understanding Ruby Method Parameters Syntax
Why Won't Ternary Operator Work with Redirect
Cannot Require 'Nokogiri' in Rails (But Works in Irb)
Pageobject with Ruby - Set Text in a Text Field Only Works in the Main File
Custom Gem Execution Fails with Nomethoderror
How to Write a Method That Counts the Most Common Substring in a String in Ruby
Sorting of 2D Array by Its Amount of in the Inner Elements
Error When Pushing to Heroku - ...Appear in Group - Ruby on Rails
Error: Missing Rvm Environment File After Doing Rvm Upgrade Command - Passenger 4.0.23
Why Does the Script Affect Everything on My Rails 3 App Even When Cased in This Code
How to Render the Ajax Response in Rails
Deleting Blank Lines After Loop
Replacing an Element in Nested Array Ruby
Modern Tools for Ruby/Rails for Building an Achievement System