Forum: Ruby Return a "complete" class

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
lordbyte (Guest)
on 2007-05-27 18:55
(Received via mailing list)

I have some problems with doing some kind of "my own controller" in
Ruby when returning a complete class.

Let's say we start with the following:

I have a ...
- ... model called Asset which has several attributes and methods.
- ... model called Picture which inherits from Asset (class Picture <
- ... model called Video which inherits from Asset

So far so good. In a gallery controller, I know trough a parameter for
which kind of assets a user wants to search (videos, pictures, ...).
Now I had the following idea, which is not working for me and clearly
has some misunderstanding of OO. :-)

I created a class called Media which looks like this (pseudo-code):

class Media
  def initialize(asset_type)
    case asset_type
      when "picture"
        return Picture
      when "video"
        return Video

In my gallery-controller, I have a before-filter similar to:
params[:media] = picture
@media =[:media])

Later, I expect to do something like:

The important thing is, that I only want to see pictures!

I see that it is not possible to return a complete class definition.
Even returning a "" doesn't give me my methods defined in
the Picture model. I also don't expect to see @media.find(:all)
working, if @media was created with a

Does anybody has hints in which direction to look or how to solve this

Thanks in advance!

lordbyte (Guest)
on 2007-05-27 19:15
(Received via mailing list)

Looks like this will solve my problem. :)
This topic is locked and can not be replied to.