What is the difference between `size` and `length` methods

Viewed 19290

When I ran size and length on a string, they returned the same value.

"akash".size # => 5
"akash".length # => 5

What is the difference between these two methods?

4 Answers

Contrary to what others have said, there is at least one differences between .length and .size in terms of usage.

.size may be used on integers, whereas .length raises a NoMethodError.

Related