ruby - Calling a method inside a method -


in recreating enumerable module practice, have #any figured out.

  def my_any?     = false     self.each |item| #i switched `each`. originally, had written `my_each`       = true if yield(item)     end       end 

now, create #none? have this, right?

  def my_none?     !(my_any?)   end 

however, when call method, error:

arr = [1,2,3] arr.my_none?{|x| x>2} localjumperror: no block given (yield) 

you using yield keyword in my_any?, requires block. can capture block given my_none? , pass along:

def my_none? &blk   !(my_any? &blk) end 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -