Can I write in this way? 17/21


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


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)


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


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.


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


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