Project

getth

0.0
No commit activity in last 3 years
No release in over 3 years
This gem defines ordinal methods *first, second, third ... ninth, tenth & last* for retrieving values from strings. Ruby Core already includes a Array#first and Array#last so only *second, third ... ninth & tenth* have been added to the Array class.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Getth

Gem Version

Introduction

This gem defines ordinal methods first, second, third ... ninth, tenth & last for retrieving values from strings. Ruby Core already includes a Array#first and Array#last so only second, third ... ninth & tenth have been added to the Array class.

With arrays

arr = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

arr.second     #=> "b"
arr.third      #=> "c"
arr.fourth     #=> "d"
arr.fifth      #=> "e"
arr.sixth      #=> "f"
arr.seventh    #=> "g"
arr.eighth     #=> "h"
arr.ninth      #=> "i"
arr.tenth      #=> "j"

With strings

str = "abcdefghij"

str.first      #=> "a"
str.first(2)   #=> "ab"

str.second     #=> "b"
str.third      #=> "c"
str.fourth     #=> "d"
str.fifth      #=> "e"
str.sixth      #=> "f"
str.seventh    #=> "g"
str.eighth     #=> "h"
str.ninth      #=> "i"
str.tenth      #=> "j"

str.last       #=> "j"
str.last(3)    #=> "hij"

When n> str.length, last(n) mimics the behaviour of Array#last by returning str:

str.last(11)   #=> "abcdefghij"

Dependencies

ordinalize gem

To Do List

  • Update gem to work for > tenth < last.

Notes

  • gem versions 0.0.2 to 0.0.5 may have gemspec dates slightly out by a few days. Just omitted to update the date before builds. Has no bearing on functionality.