-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass :x instead of block in proc leads to an error #1485
Comments
Btw, I didn't think much about this last time, but why is it a problem? After all:
|
For sure it make sense, however there is no control on how proc is called (rails internal). In short the call is made by the if filter.arity <= 0
lambda { |target, _| target.instance_exec(&filter) }
else
lambda { |target, _| target.instance_exec(target, &filter) }
end (filter being the proc) hence the arity when doing p = proc(&:upcase)
p.arity
#=> -1 when doing p = proc {|loc| loc.virtual?}
p.arity
#=> 1 |
I'll make the necessary change, as I already made one for Generally I don't want us to have to handle Rails specific stuff in a tool that's generic. |
Thanks for that, After checking rails internals, and testing stuff around (with the idea to open a rails issue), it seems like doing: after_save :geocode_and_add_city, :if => :address_changed? instead of after_save :geocode_and_add_city, :if => proc { |loc| loc.address_changed? } does work Not that it changes anything (the correction given by rubocop still fails), but it is interesting to note. Given that I don't think rails will change anything to it's implementation. Anyway thanks for reacting so promptly! |
Opening an issue for the same reason as the comment of @monfresh at the end of that issue Pass &:x? as an argument to lambda instead of a block..
here is the comment he made:
I got the very same issue:
which is flagged by rubocop (offense
Style/SymbolProc
)but if changed to
proc(&:address_changed?)
correcting the offense then the code fails:ArgumentError: no receiver given
. Basically it see the proc as taking no argument (especially not the instance) which led to the error.This should probably be ignored by rubocop.
The text was updated successfully, but these errors were encountered: