Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Return a "complete" class

Reply
Thread Tools

Return a "complete" class

 
 
lordbyte
Guest
Posts: n/a
 
      05-27-2007
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

 
Reply With Quote
 
 
 
 
lordbyte
Guest
Posts: n/a
 
      05-27-2007
Hi!

http://groups.google.com/group/comp....39ddef64babb1c

Looks like this will solve my problem.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Carriage Return added during return of large string from class method Xeno Campanoli Ruby 0 02-13-2006 08:39 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57