On 12/30/2011 08:04 PM, David Gerber wrote:
> I figured out what I need to do unless you have a better way to do
> this
I am glad you found a solution. Are you really sure you understand what
you need and what your code does?
> This is the input. The first two elements are objects. The second
> params hash is what needs to be parsed
> athlete1.merge!(athlete2,athlete3,{:athlete__nickname =>
> "gerbdla",:athlete__birthdate => "1/1/2010",:athlete__official_website
> => "
www.gerberdata.net"})
>
> here it the method
Defined in which class? In case you define this in class Hash please
not that it does have a method #merge! already - with different argument
lists and semantics. It's a bad idea to change a standard method in
such a way.
> def merge!(objects*,p_hash)
Argument objects is nowhere used in the method.
> p_hash.each do |k,v|
> obj = k.to_s.split("__")
> field = obj[1]
You only use the part after "__" so the part before is useless. Why
pass it in and go through all the hoops of splitting?
> self[field] = v
>
> end
> save!
> end
>
> this will return
> p_hash returns
p_hash is a variable; variables do not "return" anything, only methods do.
> obj = athlete
> field = athlete_birthdate
> obj = athlete
> field = official_website
>
> so basically I am splitting the object and the field name. since the
> field name can contain underscores or not like birthdate or
> official_website
> I decided to use __ to split the object from the field.
I can only repeat myself: it's still unclear to me what you want and need.
Good luck!
robert