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 538473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:02:08+00:00 2026-05-13T10:02:08+00:00

Ok, so everyone knows that capitalised identifiers are seen to be ‘constant’ in Ruby.

  • 0

Ok, so everyone knows that capitalised identifiers are seen to be ‘constant’ in Ruby.

However, it is possible to assign a new value to constants, so the following works

class A
  def self.hi; "hi"; end
end
class B
  def self.hi; "ho"; end
end
A.hi # => "hi"
B.hi # => "ho"
A = B
#  warning: already initialized constant A
# => B
A.hi # => "ho"

and also does assigning to a lowercase identifier work:

a = B
a.hi # => "ho"

However, the internal name is set to ‘B’ in all cases and the new identifier names are also only referencing ‘B’.

But if it’s technically okay for the identifier to have a lowercase name, why is this restriction on the internal name for the class? It can’t be that it needs to be constant, because it isn’t constant; so the other reason could be that lowercase identifiers have a different scope. But then: why not having a class with lowercase scope?

I’m wondering because the parser even allows for method names in unicode and such, so it seems strange that for classes it’s so much more restricted.

  • 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-13T10:02:08+00:00Added an answer on May 13, 2026 at 10:02 am

    As you said, the name of a class is that of the first constant it has been assigned to. You can only use constants with the class keyword because it has been decided that the class keyword should only be used to create named classes.

    The rationale probably being that allowing local variables would confuse uses, who would use class lowercase_class_name, not knowing the difference between lower case and upper case identifiers and then wonder why the classname was not visible everywhere (i.e. why def foo() lowercase_class_name.new end did not work).

    By making the default way to create classes specific to constants, classes defined this way will be visible everywhere and there is at least a suggestion that the value associated with that name should not change (i.e. you get a warning otherwise).

    People who know what they’re doing can still do local_variable = Class.new { ... } if they need to.

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

Sidebar

Related Questions

Possible Duplicate: Why there is not a comprehensive c archive network? Everyone knows that
Everyone knows the MessageBox.Show() method, that returns DialogResult value after dialog closed. How can
Everyone knows that: www.example.com/city/new-york is much better than: www.example.com/city?id=43567 Fine, meaningful and human-readable. But
It seems everyone knows about the dumb little but in PhoneGap that doesn't allow
Everyone knows the = sign. SELECT * FROM mytable WHERE column1 = column2; However,
Everyone knows that we should always use DOM techniques instead of regexes to extract
Everyone who's done any web application development in Scala knows that you can use
Everyone knows that Java supports data hiding. I went for an interview. Then interviewer
everyone knows that we are restricted to use the windows native fonts like arial,
By now everyone writing for Windows probably knows that applications cannot (officially) steal focus

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.