# Difference between length and length()

**URL:** <https://www.ruby-forum.com/t/difference-between-length-and-length/183886>\
**Category:** Ruby\
**Created:** [February 22, 2010, 10:26am UTC](https://www.ruby-forum.com/t/difference-between-length-and-length/183886 "2010-02-22T10:26:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nike](https://www.ruby-forum.com/u/nike)\
**Post date:** [February 22, 2010, 10:26am UTC](https://www.ruby-forum.com/t/difference-between-length-and-length/183886/1 "2010-02-22T10:26:31Z")

</div>

Hi,

Is there any difference between length and length().Pls explain

---

<div class="post-metadata">

**Author:** ![nike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nike](https://www.ruby-forum.com/u/nike)\
**Post date:** [February 22, 2010, 1:39pm UTC](https://www.ruby-forum.com/t/difference-between-length-and-length/183886/2 "2010-02-22T13:39:51Z")

</div>

Nike M. wrote:

> Is there any difference between length and length().Pls explain

In general,

foo.length  
and  
foo.length()

are the same thing. They are calling a method ‘length’ on object ‘foo’  
with no arguments.

However, a bareword ‘length’ with no receiver could be a local variable.  
Try the following in irb:

def length  
return 123  
end

length = 456  
length # this is 456, not a call to method ‘length’  
length() # this calls the method ‘length’  
self.length # so does this
