0 Replies - 1403 Views - Last Post: 16 November 2013 - 04:53 PM

#1 Lemur   User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1453
  • View blog
  • Posts: 3,633
  • Joined: 28-November 09

Enumerable Rest

Posted 16 November 2013 - 04:53 PM

Description: a = [1,2,3,4,5,6] a.first # => 1 a.car # => 1 a.head # => 1 a.rest # => [2,3,4,5,6] a.cdr # => [2,3,4,5,6] a.tail # => [2,3,4,5,6]Additions to Enumerable for collection.rest, similar to lisp cdr and haskell tail. Car and Head added as well.
module Enumerable
  def rest
    self[1..-1]
  end

  # Lisp Emulation
  alias_method :car, :first
  alias_method :cdr, :rest

  # Haskell Emulation
  alias_method :tail, :rest
  alias_method :head, :first
end


Is This A Good Question/Topic? 0
  • +

Page 1 of 1