Exploring Ruby's Global Constants and Variables - FastRuby.io | Rails Upgrade Service

By default, Ruby defines many constants and global variables that can be used in the code to get information about the current state of the application and the runtime. In this article we’ll go over most of them to understand what they are and what information we can set and get to simplify our scripts or to debug problems.Global ConstantsIn Ruby, a constant encompasses many concepts: it can be a class, a module, or a primitive value. Global constants are actually defined as constants of the Object class, so RUBY_PLATFORM and Object::RUBY_PLATFORM are equivalent.If we execute Object.constants we can get a list of all the global constants. This includes classes (like the Exception class), modules (like the JSON module), and others like RUBY_PLATFORM or ARGV that are primitives (a string and an array, respectively).Useless fact: Object is a global constant, so it’s defined as a constant inside Object itself, so Object::Object::Object is equivalent to Object.Let’s explore some of them.
Exploring Ruby's Global Constants and Variables - FastRuby.io | Rails Upgrade Service #ruby #rubydeveloper #rubyonrails #service #upgrade https://rubyonrails.ba/single/exploring-ruby-s-global-constants-and-variables-fastruby-io-rails-upgrade-service

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles