implement an each method, and get these methods for "free": : Member method « Class « Ruby






implement an each method, and get these methods for "free":

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

x = AllVowels.new
x.each { |v| puts v }

 








Related examples in the same category

1.Define a method to retrieve the value.
2.a simple demonstration of a class with two methods
3.Compare method
4.Add method to a variable only
5.Defining Methods within a Class