I have a def in ruby as shown below. Can I do something to make it DRY? as:
[e,t,l,te,le,le].each |xxx| do
if xxx
end
This means that the loops are for "Variables", not just "Enumerator".
the code:
def findLogs (obj)
if e=obj['E']
e=obj['E']['pkg'] ? "@E = #{obj['E']['pkg']},":nil
else nil
end
if t=obj['T']
t=obj['T']['pkg'] ? "@T = #{obj['T']['pkg']},":nil
else nil
end
if l=obj['L']
l=obj['L']['pkg'] ? "@L = #{obj['L']['pkg']},":nil
else nil
end
if te=obj['Te']
te=obj['Te']['pkg'] ? "@Te = #{obj['Te']['pkg']},":nil
else nil
end
if le=obj['Le']
le=obj['Le']['pkg'] ? "@Le = #{obj['Le']['pkg']},":nil
else nil
end
end
source
share