Args as params #3

Merged
merged 2 commits into from Aug 19, 2011

Projects

None yet

2 participants

@psanford
Contributor

Attached is a diff to make db.execute take bind_vars as a list of params instead of an array.
For example:

  db.execute("INSERT INTO users (id, email) VALUES (?, ?)", ['kway', 'kevin@insidesystems.net'])

becomes

db.execute("INSERT INTO users (id, email) VALUES (?, ?)", 'kway', 'kevin@insidesystems.net')
psanford added some commits Aug 19, 2011
@psanford psanford Update Database.execute to take bind_vars as params.
Instead passing execute an array (Database.execute('statement', [arg1, arg2]))
you just pass it the bind args as parameters
(Database.execute('statement', arg1, arg2)).

Removed unnecessary &block from execute; block_given? and yield work
on the implicit block.
4c97729
@psanford psanford Update readme with execute param syntax. 734825a
@kreynolds kreynolds merged commit 502c2e0 into kreynolds:master Aug 19, 2011
@kreynolds
Owner

I know there is an implicit block but I like to explicitly state it as it makes the function clear when scanning generated documentation .. I'm old fashioned that way. Thanks.

@psanford
Contributor

You should be aware that there is a performance penalty in explicitly naming that block even if you never use it. See http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html

@kreynolds
Owner

So there is, I had not seen that before. I will remove them.

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