In my app, we have Users who can perform actions on one another - like poking on Facebook.
I'm writing the methods just now and am not really sure which approach to take. I mean, I know they're both acceptable but is there a more idiomatic approach?
if @current_user.may_poke?(@other_user)
@current_user.poke!(@other_user)
end
if @current_user.may_poke?(@other_user)
@other_user.poke!(@current_user)
end
The first option reads better in English, almost perfectly as a sentence.
The second option makes more sense in terms of method naming, "poke" is a method being performed on the @other_user
. The @current_user
is just an argument to provide extra info - who did the poking.
I'd stick with Option 1 there.. if you follow the logic of the conditional, then you're asking "If current_user may poke other_user, then have current_user poke other_user". Option 2 doesn't make much sense when thought of in those terms.
Also.. matz, the author of Ruby, states that "The bang [exclamation point] sign means "the bang version is more dangerous than its non bang counterpart; handle with care"." ( http://www.ruby-forum.com/topic/176830#773946 ). I'd probably just use poke
for that method name instead of poke!
.