Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.48 KB | None | 0 0
  1.   def method_missing(method_name, *args, &block)
  2.     if method_name =~ /^swap_(.+)_with(!?)$/
  3.       property = $1
  4.       is_bang  = $2 == '!'
  5.       sibling  = args[0]
  6.  
  7.       old_sibling_property = sibling.send(property)
  8.       old_self_property    = self.send(property)
  9.       puts property
  10.       sibling.send("#{propery}=", old_self_property)
  11.       self.send("#{property}=", old_sibling_property)
  12.  
  13.       [self, sibling].collect(&:save) if is_bang
  14.       return self
  15.     end
  16.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement