Logo

Programming-Idioms

Assign to the variable x the last element of the list items.
Implementation
Ruby

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Ruby implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
x := items[len(items)-1]
const x = items[items.length - 1];
x = items[-1]
x = items[-1]
x := items[high(items)];
val x = items.last
foo :: [a] -> Maybe a
foo [] = Nothing
foo xs = Just $ last xs

x = foo items
int[42] items;
int x = items[$-1];
import std.range;
int[] items;
auto x = items.back();
x = items.last;
local x = items[#items]
let x = items[items.len()-1];
my $x = $items[-1];
$x = end($items);
let x = items.last().unwrap();
using System.Linq;
var x = items.LastOrDefault();
x = List.last(items)
int x = items[items.length - 1];
x = lists:last(items),
x = last items
(def x (last items))
#include<vector>
std::vector<int> items;
int last = items.back();
x = items(ubound(items,1))
var x = items.last()
$x = $items[array_key_last($items)];
#include <iterator>
auto x = *std::crbegin(items);
my $x = $items[$#items];
Dim x = items(items.Count - 1)
(def x (peek items))
var x = items[items.Count-1];
@import Foundation;
x=items.lastObject;
int length = sizeof(items) / sizeof(items[0]);
int x = items[length - 1];
X := Items'Last
(define items (list 1 2 3 4))
(define x (last items))
(setf x (car (last items)))
var x = items[^1];
const x = items.at(-1);
x := items last.
def x = items.last()