# Gem & Classes

**URL:** <https://www.ruby-forum.com/t/gem-classes/159479>\
**Category:** Ruby\
**Created:** [February 4, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/gem-classes/159479 "2009-02-04T22:53:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [February 4, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/gem-classes/159479/1 "2009-02-04T22:53:37Z")

</div>

I’m confused with the difference between gems and classes. Are they  
considered the same thing? I familiar with what a class is, but where do  
gems fall into place. Do you use them sort of like an include in C\C++?.  
Can someone give me a simple example.

What about Modules? How are they used in Ruby?

Thanks  
Zayd

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [February 4, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/gem-classes/159479/2 "2009-02-04T23:06:52Z")

</div>

El MiÃ©rcoles, 4 de Febrero de 2009, Zayd C. escribiÃ³:

> I’m confused with the difference between gems and classes. Are they  
> considered the same thing? I familiar with what a class is, but where do  
> gems fall into place. Do you use them sort of like an include in C\C++?.

Gems are just a way to package a Ruby library/module, no more.

> What about Modules? How are they used in Ruby?

You should start by reading some Ruby book 😉

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [February 4, 2009, 11:09pm UTC](https://www.ruby-forum.com/t/gem-classes/159479/3 "2009-02-04T23:09:48Z")

</div>

2009/2/4 Zayd C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’m confused with the difference between gems and classes. Are they  
> considered the same thing? I familiar with what a class is, but where do  
> gems fall into place. Do you use them sort of like an include in C\C++?.  
> Can someone give me a simple example.
> 
> What about Modules? How are they used in Ruby?

A module serves as namespace or as mixin (essentially  
a bag of methods).

A class is a module (really, Class inherits from Module)  
that can be instantiated. Every object has a class that  
was used to instantiate it (you can get it with the “class”  
method).

There is no such thing as a “gem” on the language  
level. A gem is a package of Ruby code. It can package  
any number of modules, classes, source files, and  
associated data files.

The require function is used to load source files. It looks for  
source files on the load path ($LOAD\_PATH). In order for  
require to find source files installed as gem, you have  
to load the gem (require “rubygems”; gem “some-gem”).

Ruby 1.9 ships with RubyGems and source files from gems  
are automatically on the load path.

HTH,  
Stefan

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [February 4, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/gem-classes/159479/4 "2009-02-04T23:32:05Z")

</div>

Okay Cool!! Understood 🙂 Thanks Guys. I need to put in some more Ruby  
time

On Wed, Feb 4, 2009 at 5:09 PM, Stefan L. \<

---

<div class="post-metadata">

**Author:** ![devrubygem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@devrubygem](https://www.ruby-forum.com/u/devrubygem)\
**Post date:** [February 5, 2009, 1:30am UTC](https://www.ruby-forum.com/t/gem-classes/159479/5 "2009-02-05T01:30:25Z")

</div>

Gems are packages of code. Classes are part of how you write code.

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)
