Can I write in this way? 17/21


#1



I tried to write it in this way below but I dont know why the code is incorrect and result in error message. Could someone help?


odds_n_ends = [:weezard, 42, "Trady Blix", 3, true, 19, 12.345]

ints = odds_n_ends do |x|
    if x.is_a? Integer
       x.select
    end
end


#2

Why it does what instead of what?

(please avoid the word "work", it replaces describing the situation)

Running your code results in a pretty straight-forward error message which explains what problem was encountered while running the code

aoeu.rb:3:in `<main>': undefined method `odds_n_ends' for main:Object (NoMethodError)

#3

Hi could you kindly explain what is the error message talking about ?


#4

when you use keyword do it looks at what stands before do. It sees odds_n_ends, the interpreter doesn't know what to do since it expected iterator, like each.


#5

It's saying that you instructed ruby to call a method by that name, but it was unable to do so because no such method exists. In other words you'll want to either not call a method by that name since you don't have a method by that name, or you'll want to create such a method before you try to use it


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.