Ruby on Rails
Sunday, July 12, 2015
Okay, I have been following this for a while. I am writing here respectfully of other contributors. It is just that I see the matter differently, and I am wondering why none of you have suggested inheritance.
You have a car. And that car has a model and has a price. Anyway in your application, you will store, one by one, a car model and its price.
Your class should look like this:
class Auto
attr_accessor :model, :price
def initialize(model_value, price_value)
@model = model_value
@price = price_value
end
end
That's it for class Auto. You are basically using class Auto for storage
Introduce a new class, using inheritance
class Auto_Calculations < Auto
def calculate_percent(...)
end
def calculate_percent_plus_itself(...)
end
end
Just seems to me that the failure in this fellow's code is that he is combining two data instances in one class.
I might me totally wrong... Just offering
Liz
-- You have a car. And that car has a model and has a price. Anyway in your application, you will store, one by one, a car model and its price.
Your class should look like this:
class Auto
attr_accessor :model, :price
def initialize(model_value, price_value)
@model = model_value
@price = price_value
end
end
That's it for class Auto. You are basically using class Auto for storage
Introduce a new class, using inheritance
class Auto_Calculations < Auto
def calculate_percent(...)
end
def calculate_percent_plus_itself(...)
end
end
Just seems to me that the failure in this fellow's code is that he is combining two data instances in one class.
I might me totally wrong... Just offering
Liz
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/1ae84bad-1854-4233-a509-aaa7a572c205%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment