get Enumerable involved : Enumerable « Collections « Ruby






get Enumerable involved


class AllVowels
  include Enumerable

  @@vowels = %w{a e i o u}
  def each
    @@vowels.each { |v| yield v }
  end
end

x = AllVowels.new
x.collect { |i| i + "x" }
x.detect { |i| i > "j" }
x.select { |i| i > "j" }
x.sort
x.max
x.min

 








Related examples in the same category

1.Sorting an Array by Frequency of Appearance
2.Add cartesian to Enumerable
3.Building a Histogram
4.Call each a number of times
5.randomly each
6.Writing Block Methods that Classify or Collect
7.Implementing Enumerable - Write One Method, Get 22 Free
8.Enumerable.instance_methods.sort
9.Sort on two arrays