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
Post a Comment