Constant: Rails::VERSION::STRING
I know how to find the version of rails I have:
> Rails::VERSION::STRING
> "2.3.2"
- Can someone breakdown/explain Rails::VERSION::STRING" for me?
- What is the first part "Rails"?
- What does the "::" mean/do?
- Is this a global constant开发者_运维技巧?
- How is this different from "RUBY_VERSION"? (construction, not meaning. ie no "::")
- How can I list/find all global constants?
Thanks.
Rails is a Module. :: Gives you access to a static member or method of a module, as compared to the dot operator, which calls methods on the module object. (All classes are objects in Ruby.) STRING is, similarly, a static member of VERSION.
These act like global constants (they're constant and there is only one copy of them) but they aren't global constants in the usual meaning of that term in Ruby. They're static fields on the Rails module.
They are scoped so locally to avoid polluting the global namespace. RUBY_VERSION is in the global namespace. Since it is a core language feature, nobody cares so much that they can't use that name for their own purposes, but other packages should avoid putting stuff there.
'Rails.constants' will give you the other Rails constants.
精彩评论