Been around a blocks few times


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
It says 42 should be in ints but it isn’t. What I’m missing ?


odds_n_ends = [:weezard, 42, “Trady Blix”, 3, true, 19, 12.345]
ints = {is_a? Integer}

<do not remove the three backticks above>

I’m bit of a tourist when it comes to Ruby, but I think that checks if the main object is an integer. It’s not. See Array#select’s documentation for an example:

This is updated code:

odds_n_ends = [:weezard, 42, “Trady Blix”, 3, true, 19, 12.345]
ints = {|odds_n_ends| is_a? Integer}

but still getting the same error … this should work though … syntax should be ok …

Your block names a parameter now, but ignores it
It’s also questionable to name it the same as a variable that represents something very different.

Consider what the block should do.

It receives one value, and should determine if it should be included.

Your block is doing something similar to this right now:

def add a, b

puts add 5, 6  # outputs 42, but I expect 11

That method ignores the arguments given to it and just returns 42. It’s a fairly useless method, it doesn’t say anything about the sum of a and b.

This is a bit of an old thread, but if by chance you still haven’t solved it. I was having the same trouble and it finally came to me with ionatan’s comment about ignoring the parameter.

if you have a block with a parameter then you also need to use that parameter in the block.
for example:
it would be times_2 = some bit of code { |x| x * 2 }
not times_2 = some bit of code { |x| * 2 }

Hope that helps to clear it up.