when '=' can be used just after 'if' in Ruby/Rails? -
i have noticed metod, while looking through activemodel::serializable
def as_json(args={}) if root = args[:root] || options[:root] options[:hash] = hash = {} options[:unique_values] = {} hash.merge!(root => serialize) include_meta hash hash else serialize end end
and dont know how 'if root =' works... shouldn't 'if root =='?
if root = args[:root] || options[:root]
this assign value of args[:root]
root
if args[:root]
not nil
. if nil
, assign options[:root]
root. if final result of root
not nil
, first branch of if
taken. if nil
, else
branch taken.
Comments
Post a Comment