Friday, May 24, 2013

[Rails] Class design Help!

I have 3 classes ("Truck", "Semi", "Motorcycle") that all inherit from
the "Vehicle" class.
Each subclass has an attribute for "Wheels" that tells how many wheels
the vehicle has (I do not store these values in the database because
they will never change)

I'm wondering what is the preferred method for handling this? Right now
I have individual methods in each class for "Wheels":

For example:

class Truck
def wheels
4
end
end

class Motorcycle
def wheels
2
end
end

class Semi
def wheels
18
end
end

Is there a better way??? Thanks

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d1fc7e559a885e015f3369f37ac34838%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate