-austin
is probably a good. one. If you can post some Ruby code that would rely
on something like this that would be great. Maybe the folks on the list
can help you find a solution for you.
Hmmm… Maybe I beginning to understand your point. The task was: before
serializing (or storing in DB) some complex class, ensure that all
fields
aren’t nil. I does some metaprogramming, so description of the fields
looked
like:
class Something
data :name, String, :default => ‘’
data :price, Float, :default => 0.0
data :quan, Fixnum, :default => 0
data :type, String, :default => ‘unknown’
data :coef, Float , :default = > 1.0
def store_in_db
self.validate!
…
end
def validate! #ensure each field isn’t nil and has right type; #set it’s value to default in other case
end
end
(I hope the code above is quite self-explaining.)
Later I saw that most of default values seems to like “empty value” of
the
corresponding type (I was C++ guy, remember). So, I want not to write
:default => … for :name, :price, :quan
But after this topic (and Austins and yours answers) I think that
overall
construction don’t looks very rubyish. Maybe, I must look for
alternatives.
I think that Austin’s question about what you are trying to accomplish
is probably a good. one. If you can post some Ruby code that would rely
on something like this that would be great. Maybe the folks on the list
can help you find a solution for you.