Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:34:43+00:00 2026-05-27T21:34:43+00:00

in all the tutorials for RoR I see instances where the coder chose to

  • 0

in all the tutorials for RoR I see instances where the coder chose to use Proc.new when seemingly it is both unnecessary and rather unattractive.

Example, here is a callback for placed in a model, one using Proc.new the other presumably doing the same thing:

class Order < ActiveRecord::Base  
  before_save :normalize_card_number,  
    :if => Proc.new { |order| order.paid_with_card? }  
end

class Order < ActiveRecord::Base
  before_save :normalize_card_number, :if => "paid_with_card?"
end

So what’s the difference? Why use the Proc? Don’t they both call the “paid_with_card?” method?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:34:44+00:00Added an answer on May 27, 2026 at 9:34 pm

    In the example above, using a symbol for the conditional method would probably be the best choice.

    class Order < ActiveRecord::Base
      before_save :normalize_card_number, :if => :paid_with_card?
    end
    

    The string option uses eval to evaluate the Ruby code in the string. So personally, I would prefer to use a symbol if calling a method or a Proc if writing a short inline condition.

    Per the RailsGuides documentation:

    Using a Proc object gives you the ability to write an inline condition instead of a separate method. This option is best suited for one-liners.

    I think using a Proc might be better illustrated this way:

    class Order < ActiveRecord::Base
      before_save :normalize_card_number,
        :if => Proc.new { |order| order.payment_type == "card" }
    end
    

    This would possibly eliminate the need for the paid_with_card? method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All the tutorials I have seen seem to use *.jsf , *.faces , or
When I first started reading about Python, all of the tutorials have you use
Almost all of the examples in the jQuery tutorials that I've read, usually use
Django tutorials everywhere use constant-set application name all around - in urls file, in
All of the tutorials I've seen so far for RoR have shown me generating
New to all coding worlds and new to RoR. I have been doing a
In all tutorials about MVVM, I see code behind file is of no great
I'm learning Eclipse PDT for PHP development. In pretty much all tutorials I've read
All the tutorials and examples I've found of XSLT processing seem to assume your
This is very dumb - but I've seen all the tutorials and guides -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.