ruby on rails - Loop through each element from third to last of active record object -


i have active record object of array.

@obj = user.post 

now want loop through @obj third element last. want below

@obj.third-to-last.each  #output here end 

i can using counter , if else condition. want know if there better , simple way this.

use array#drop method drop first 2 elements of @obj:

@obj.drop(2).each |obj|   # whatever... end 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -