I have a hash (the real one is much bigger)
parsed = {"follower_count" => 500, "something_else" => "etc", "xyz" => "abc"}
and a class hanging around that looks like this
class Company
attr_accessor :followers
def initialize(thehash)
@followers = thehash['follower_count']
end
end
So lastly there is this code which throws the error before I can worry about anything else going wrong
>> parsed.map {|t| Company.new(t)}
TypeError: can't convert String into Integer
from (irb):7:in `[]'
from (irb):7:in `initialize'
from (irb):12:in `new'
from (irb):12
from (irb):12:in `map'
from (irb):12:in `each'
from (irb):12:in `map'
from (irb):12
When you iterate over a Hash, the block gets an array as its argument and that array contains (in order) the key and value for one pair in the Hash. So, in here:
tis actually a two element array and is usually written:Then, inside
Company#initialize, you’re treatingtas a Hash when it is actually a two element Array.You don’t want to use
maponparsedat all, you just want toCompany.new(parsed).