Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
Created August 9, 2012 17:18
Show Gist options
  • Save stevenbristol/3306075 to your computer and use it in GitHub Desktop.
Save stevenbristol/3306075 to your computer and use it in GitHub Desktop.
Proc in scope
class User < ActiveRecord::Base
scope :hello_lamb, ->(param) { param.blank? ? where("") : where("param = ?", param) }
scope :hello_proc, Proc.new { |param| param.blank? ? where("") : where("param = ?", param) }
end
User.hello_proc
# User Load (0.5ms) SELECT * FROM users
User.hello_lamb
#ArgumentError: wrong number of arguments (0 for 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment