Are there ruby equivalents to car, cdr, and cons?

Viewed 4591

Are there ruby equivalents to the lisp car, cdr, and cons functions? For those unfamiliar with lisp, here's what I want from ruby:

[1,2,3].car   => 1
[1,2,3].cdr   => [2,3]
[2,3].cons(1) => [1,2,3]

(in lisp):

(car '(1 2 3))  => 1
(cdr '(1 2 3))  => (2 3)
(cons 1 '(2 3)) => (1 2 3)
5 Answers
Related