lib/rext/string/helpers.rb in visionmedia-rext-0.0.3 vs lib/rext/string/helpers.rb in visionmedia-rext-0.0.4

- old
+ new

@@ -174,19 +174,31 @@ def singular? !plural? end ## - # First character. + # First +n+ character(s). + # + # === Examples + # + # 'foo'.first # => f + # 'foo'.first(2) # => fo + # - def first - self[0,1] + def first n = 1 + self[0,n] end ## - # Last character. - - def last - self[-1, 1] + # Last +n+ character(s). + # + # === Examples + # + # 'bar'.last # => r + # 'bar'.last(2) # => ar + # + + def last n = 1 + self[-n, n] end end