Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/extensions/string.rb
Overview
TODO: Get these added to the pretty_ruby gem, and use that. (Note that it uses refinements, not monkey-patching.)
Instance Method Summary collapse
- #drop(count = 1) ⇒ Object
-
#first(count = 1) ⇒ Object
Allow Scheme-style
first. - #last(count = 1) ⇒ Object
-
#rest(count = 1) ⇒ Object
Allow Scheme-style
rest. -
#tail ⇒ Object
Allow Scheme-style
tail.
Instance Method Details
#drop(count = 1) ⇒ Object
15 16 17 |
# File 'lib/extensions/string.rb', line 15 def drop(count = 1) self.chars.drop(count).join end |
#first(count = 1) ⇒ Object
Allow Scheme-style first.
6 7 8 |
# File 'lib/extensions/string.rb', line 6 def first(count = 1) self[0..(count - 1)] end |
#last(count = 1) ⇒ Object
25 26 27 |
# File 'lib/extensions/string.rb', line 25 def last(count = 1) self.chars.last(count).join end |
#rest(count = 1) ⇒ Object
Allow Scheme-style rest.
11 12 13 |
# File 'lib/extensions/string.rb', line 11 def rest(count = 1) drop(count) end |
#tail ⇒ Object
Allow Scheme-style tail.
20 21 22 23 |
# File 'lib/extensions/string.rb', line 20 def tail return self if size.zero? last(size - 1) end |