<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/ruby-beginner-en-L3ZCI/3/1?curriculum_id=5059f8619189a5000201fbcb#
<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 = odds_n_ends.select {is_a? Integer}
<do not remove the three backticks above>
markiscoding:
{is_a? Integer}
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:
http://ruby-doc.org/core-2.2.0/Array.html#method-i-select
This is updated code:
odds_n_ends = [:weezard, 42, “Trady Blix”, 3, true, 19, 12.345]
ints = odds_n_ends.select {|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
42
end
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.
4 Likes