Return a "complete" class

Discussion in 'Ruby' started by lordbyte, May 27, 2007.

  1. lordbyte

    lordbyte Guest

    Hi!

    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 <
    Asset)
    - ... 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
    end
    end
    end

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

    Later, I expect to do something like:
    @media.find:)all)

    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 "Picture.new" 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 Picture.new.

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

    Thanks in advance!

    Cheers
    Markus
     
    lordbyte, May 27, 2007
    #1
    1. Advertising

  2. lordbyte

    lordbyte Guest

    lordbyte, May 27, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,792
    Thomas Weidenfeller
    Oct 12, 2005
  2. christopher diggins
    Replies:
    16
    Views:
    756
    Pete Becker
    May 4, 2005
  3. Greenhorn
    Replies:
    15
    Views:
    834
    Keith Thompson
    Mar 6, 2005
  4. Xeno Campanoli
    Replies:
    0
    Views:
    231
    Xeno Campanoli
    Feb 13, 2006
  5. Jenda Krynicky

    ri slownes and complete class docs

    Jenda Krynicky, Mar 15, 2007, in forum: Ruby
    Replies:
    1
    Views:
    77
    Jan Svitok
    Mar 15, 2007
Loading...

Share This Page