ruby - How do I display both the first and last elements of an array? -


i want return first , last elements of array.

def first_and_last(a)   a.first   a.last end 

but it's displays last element , when put plus sign adds elements. want print this[1,3]. suggestions?

another way:

['cat', 'dog', 'pig'].values_at(0,-1)   #=> ["cat", "pig"]  

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -