You are here: Forums Ask a Rails expert Usage of PROC objects...
Posted in Forums : Ask a Rails expert
Authority 12
Posting Rating 89
Sign in to rate this post
|
In some of the Ruby tutorials PROC are explained as callable objects in ruby and they are not executed unless called explicitly. Like pr = Proc.new { puts “Hello World” } This statement is not executed at this point But if we do pr.call it results in => Hello World I would like to know how this works in our model validations suppose we have validates_length_of :user_name, :maximum => 40,:if => Proc.new { |user| !user.user_name.blank? } so to do this validation we have specified a condition using a Proc block but how is this Proc block called ? is the call to Proc block made internally by rails? |
Authority 12
Posting Rating 91
Sign in to rate this post
|
\lib\ruby\gems\1.8\gems\activerecord-1.15.3\lib\active_record\validations.rb(from line 260):
|
Authority 12
Posting Rating 89
Sign in to rate this post
|
Thanks for the reply Marcin |
Authority 12
Posting Rating 91
Sign in to rate this post
|
I’m glad you found this helpful Balaji:) |
Ask a Rails expert : how to execute the url from my controller
Ask a Rails expert : conditional action caching multiple mongrel clusters
Ask a Rails expert : Using like command in RoR
Ask a Rails expert : Apache ActionController:RoutingError
Ask a Rails expert : Multiple csv file upload based on data in a form
Ask a Rails expert : Exception error code
Ask a Rails expert : Tracking down an issue
Ask a Rails expert : Thread Vs Transaction
Ask a Rails expert : implementing whitelist plugin
Ask a Rails expert : Validation helper