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

  • Home
  • SEARCH
  • 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 6967763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:21:49+00:00 2026-05-27T16:21:49+00:00

I am a Objective-c programmer so I am not used to having code outside

  • 0

I am a Objective-c programmer so I am not used to having code outside of methods.

I have a two-part question about Rail’s validates.

Consider this code:

class User < ActiveRecord::Base
  attr_accessible :name, :email

  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates :name,  :presence   => true,
                    :length     => { :maximum => 50}

  validates :email, :presence   => true,
                    :format     => { :with => email_regex }.
                    :uniqueness => true

end
  1. When exactly is the validates method executed? Upon instantiating a User instance or when its class definition is loaded?
  2. When does the User actually get validated? When I save the User instance or create it?
  • 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-27T16:21:50+00:00Added an answer on May 27, 2026 at 4:21 pm

    All of the calls within the class definition are called when the class definition is executed, not when an instance is created. It is worth mentioning that the variable email_regex is not a instance variable, but rather a local variable to the class definition.

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

Sidebar

Related Questions

I'm an objective-c programmer and I'm wondering how low should I go (methods wise).
I'm a first time Objective C programmer. I've been reading other people's code and
I am an experienced programmer in C, yet not objective c. I am trying
I am a Java programmer, learning Objective-C and I have a problem with implementation
Several questions about accessor methods in C++ have been asked on SO, but none
I'm originally a Java programmer who now works with Objective-C. I'd like to create
Possible Duplicate: Calling Python from Objective-C I'm a long-time Python programmer and short-time Cocoa
Objective: In support of a Windows Service that may have multiple instances on a
Let me setup my question with some info. I'm not in college yet and
There have been some discussions on how to organize your #import statements in objective-c.

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.