Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Hossam Khalifa
Hossam Khalifa
17,200 Points

passing ruby blocks around

I want to make the my_all? method use the my_select and get the arrays length(that is returned by my_select) and compare it with the arrays length. I get this error

my_enum.rb:17:in `my_select': wrong number of arguments (1 for 0) (ArgumentError)
        from my_enum.rb:24:in `my_all?'
        from my_enum.rb:34:in `<main>'
module Enumerable
  def my_each
    for el in self
      yield(el)
      el
    end
  end

  def my_each_with_index
    i = 0
    for el in self
      yield(el,i)
      i+=1
    end
  end

  def my_select(&block)
    arr = []
    self.my_each{|el| arr << el if block.call(el) }
    arr
  end
  def my_all?(&block)
    true if (self.my_select block.call).length == self.length
  end
  def my_none?
    !self.my_all?
  end
end


p [1,2,3,4,4,5].my_all?{|el| el == 4}