Skip to content

Instantly share code, notes, and snippets.

@MSch
Created November 24, 2010 21:43
Show Gist options
  • Select an option

  • Save MSch/714483 to your computer and use it in GitHub Desktop.

Select an option

Save MSch/714483 to your computer and use it in GitHub Desktop.
module ActiveRecord
class Relation
def find_or_create
if self.exists?
self.first
else
self.create
end
end
end
end
User.where(:email => '[email protected]').find_or_create
Todo.where(:title => 'test').find_or_create
@tosh
Copy link

tosh commented Nov 24, 2010

      end 
    end
  end
end

scnr ;)

@MSch
Copy link
Author

MSch commented Nov 24, 2010

At least Ruby has open classes :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment