# Containers

**URL:** <https://www.ruby-forum.com/t/containers/158358>\
**Category:** Ruby\
**Created:** [January 22, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/containers/158358 "2009-01-22T13:00:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raju](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@raju](https://www.ruby-forum.com/u/raju)\
**Post date:** [January 22, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/containers/158358/1 "2009-01-22T13:00:31Z")

</div>

Hai,

```
  I have a problem with ruby containers.what is the differnce

```

between containers and classes.Is there any syntax for containers.can  
you please  
reply me.

---

<div class="post-metadata">

**Author:** ![raju](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@raju](https://www.ruby-forum.com/u/raju)\
**Post date:** [January 22, 2009, 1:45pm UTC](https://www.ruby-forum.com/t/containers/158358/2 "2009-01-22T13:45:01Z")

</div>

Subbaraju Datla wrote:

> Hai,
> 
> ```
> I have a problem with ruby containers.what is the differnce
> 
> ```
> 
> between containers and classes.Is there any syntax for containers.can  
> you please  
> reply me.

AFAIK ‘container’ is just a general word for the classes that let you  
contain objects: Hash and Array are the most commonly used example, but  
you have others such as Queue. You could also view String as a  
container class as it ‘contains’ characters.

There’s no ‘Container’ class, so there’s no syntax for containers,  
although the classes that are referred to as containers (Hash, Array,  
String etc) may define some common methods such as size (aka length).  
This isn’t required though.

---

<div class="post-metadata">

**Author:** ![raju](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@raju](https://www.ruby-forum.com/u/raju)\
**Post date:** [January 22, 2009, 10:36pm UTC](https://www.ruby-forum.com/t/containers/158358/3 "2009-01-22T22:36:02Z")

</div>

On 22.01.2009 13:43, Max W. wrote:

> Subbaraju Datla wrote:
> 
> > Hai,

Shark?

> > ```
> > I have a problem with ruby containers.what is the differnce
> > 
> > ```
> > 
> > between containers and classes.Is there any syntax for containers.can  
> > you please  
> > reply me.
> 
> AFAIK ‘container’ is just a general word for the classes that let you  
> contain objects: Hash and Array are the most commonly used example, but  
> you have others such as Queue. You could also view String as a  
> container class as it ‘contains’ characters.

I’d add: it’s typical for a container class to contain arbitrary many  
instances of other classes.

> There’s no ‘Container’ class, so there’s no syntax for containers,  
> although the classes that are referred to as containers (Hash, Array,  
> String etc) may define some common methods such as size (aka length).  
> This isn’t required though.

Adding to that there _is_ special syntax in Ruby, namely

this\_is\_a\_hash = {1=\>2, 3=\>4}  
this\_is\_an\_array = [1,234,23,2]

Kind regards

robert
