To find the length of a string in Ruby, you can use any of the following three methods:
length
: This method returns the length of the string.main.rb43 chars3 lines
size
: This method is an alias of length
method. It also returns the length of the string.main.rb41 chars3 lines
count
: This method can also be used to find the length of the string by passing ''
as an argument.main.rb50 chars3 lines
All three methods achieve the same result, so use the one that you find most readable and convenient.
gistlibby LogSnag