Skip to content

sagar-ruby/getth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Access elements from Array objects using methods: second, third, fourth upto tenth. Access characters from String objects in the same way.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages