Class: String
Overview
A few core extensions brought over from ActiveSupport. These are handy for parsing.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #first(limit = 1) ⇒ Object
- #last(limit = 1) ⇒ Object
- #squish ⇒ Object
- #squish! ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
56 57 58 |
# File 'lib/sinew/core_ext.rb', line 56 def blank? !!(self =~ /\A\s*\z/) end |
#first(limit = 1) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/sinew/core_ext.rb', line 17 def first(limit = 1) if limit == 0 '' elsif limit >= size dup else self[0..limit - 1] end end |
#last(limit = 1) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/sinew/core_ext.rb', line 27 def last(limit = 1) if limit == 0 '' elsif limit >= size dup else self[-limit..-1] end end |
#squish ⇒ Object
7 8 9 |
# File 'lib/sinew/core_ext.rb', line 7 def squish dup.squish! end |
#squish! ⇒ Object
11 12 13 14 15 |
# File 'lib/sinew/core_ext.rb', line 11 def squish! strip! gsub!(/\s+/, ' ') self end |