This is my code:
my_array = ["raindrops", :kettles, "whiskers", :mittens, :packages]
# Add your code below!
symbol_filter = lambda {|x| if(x.is_a? Symbol) puts x end}

I want to create a lambda which will filter for symbols in the array.
This is my code:
my_array = ["raindrops", :kettles, "whiskers", :mittens, :packages]
# Add your code below!
symbol_filter = lambda {|x| if(x.is_a? Symbol) puts x end}

I want to create a lambda which will filter for symbols in the array.
The error is as follows:
syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
And it is pointing at puts, which means puts is what was unexpected.
So the solutions are to give it what it expects
if ( x.isA? Symbol ) then puts x end
if ( x.isA? Symbol ); puts x end
if ( x.isA? Symbol )
puts x
end
As a side, there is another syntax for one-liners like this
puts x if ( x.isA? Symbol )
When using if conditions in one single line, you have to end your if header with a ';'. However I would highly recommend against those ifs. Moreover you should write something like this:
if x.is_a?(Symbol)
p x
end
or use the proper inline syntax:
p x if x.is_a?(Symbol)
Back to your problem, what do you want to achieve? Find all symbols in the array? Then you should use select on that array