Code Snippet: Quick Method Forwarding

Quick Method Forwarding class CardHand include Enumerable def initialize (.player, cards') @player = player @cards = cards end def eachf ... ) = @cards.each( ... ) end hand = CardHand. new "Avdi" , ["2 ", "Ko"] hand, grep /&/ # => [‘K@"] With Ruby 3's "endless methods" and ellipsis ( ... ) operator, forwarding methods is easier than ever.

Responses