Forum: Ruby Gem & Classes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
78947e02afdcaabbda360f9d112bfbe0?d=identicon&s=25 Musdev Musdev (devrubygem)
on 2009-02-04 22:53
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
0f1f17ba297242e9d3c86d4cc0a6ea85?d=identicon&s=25 Iñaki Baz Castillo (Guest)
on 2009-02-04 23:06
(Received via mailing list)
El Miércoles, 4 de Febrero de 2009, Zayd Connor 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 ;)
40613e55d7082e5f08429dfb50d0680e?d=identicon&s=25 Stefan Lang (Guest)
on 2009-02-04 23:09
(Received via mailing list)
2009/2/4 Zayd Connor <devrubygem@gmail.com>:
> 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
78947e02afdcaabbda360f9d112bfbe0?d=identicon&s=25 Musdev Musdev (devrubygem)
on 2009-02-04 23:32
(Received via mailing list)
Okay Cool!! Understood :) Thanks Guys. I need to put in some more Ruby
time




On Wed, Feb 4, 2009 at 5:09 PM, Stefan Lang <
3131fcea0a711e5ad89c8d49cc9253b4?d=identicon&s=25 Julian Leviston (Guest)
on 2009-02-05 01:30
(Received via mailing list)
Gems are packages of code. Classes are part of how you write code.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
This topic is locked and can not be replied to.