Skip to content

Instantly share code, notes, and snippets.

Created February 16, 2014 22:25
Show Gist options
  • Save anonymous/9041516 to your computer and use it in GitHub Desktop.
Save anonymous/9041516 to your computer and use it in GitHub Desktop.
Can someone help write a standalone method that produces this output?
s = %W/This
is
a
test./
print "Number of lines: ", count_lines(s), "\n"
# Output:
Number of lines: 4
@havenwood
Copy link

def count_lines string
  string.lines.size
end

count_lines "hi\nthere"
#=> 2

def print_line_count string
  puts "Number of lines: #{count_lines string}"
end

print_line_count "hi\nthere"
# Number of lines: 2
#=> nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment