Method: UpdateOrCreate::ClassMethods#update_or_create

Defined in:
lib/update_or_create.rb

#update_or_create(search, *args) {|obj| ... } ⇒ Object

Yields:

  • (obj)


19
20
21
22
23
24
25
26
# File 'lib/update_or_create.rb', line 19

def update_or_create(search, *args, &block)
  parameters = search.split("_and_")
  params = Hash[ parameters.zip(args) ]
  obj = where(params).first || self.new(params)
  yield obj
  obj.save
  obj
end