Class: String

Inherits:
Object show all
Defined in:
lib/ohm/compat-1.8.6.rb

Direct Known Subclasses

Ohm::Key

Instance Method Summary (collapse)

Instance Method Details

- (Object) lines(separator = $/)

This version of String#lines is almost fully compatible with that of Ruby 1.9. If a zero-length record separator is supplied in Ruby 1.9, the string is split into paragraphs delimited by multiple successive newlines. This replacement ignores that feature in favor of code simplicity.



9
10
11
12
13
# File 'lib/ohm/compat-1.8.6.rb', line 9

def lines(separator = $/)
  result = split(separator).map { |part| "#{part}#{separator}" }
  result.each { |r| yield r } if block_given?
  result
end