They are equivalent if the receiver of the method is the object being checked. This is not quite the way ActiveModel validators work, but the concept is similar:
Calling to_proc on a character :sym gives you the functional equivalent β β (x) {x.sym} - the character is sent as a message to the proc argument. Calling to_proc in proc just returns itself, so you can pass either a character or proc to a method and guarantee proc:
def return_a_proc(symbol_or_proc) symbol_or_proc.to_proc end
In cases where the model instance is not a receiver, for example. the validation method takes the model as an argument or, as in Daniel Evans's example, you need to explicitly build proc to indicate what should be done with the proc argument.
source share