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 -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -