ruby global property from object

Accessing a Global Property in Ruby

To access a global property in Ruby, you can use the $ symbol followed by the name of the global variable. Here are the steps to access a global property in Ruby:

  1. Declare a global variable: First, you need to declare a global variable. Global variables in Ruby start with a $ symbol. For example, let's declare a global variable called $message and assign it a value:

ruby $message = "Hello, world!"

  1. Access the global variable: To access the global variable, you can simply use the $ symbol followed by the variable name. For example, to access the value of the $message global variable, you can use:

ruby puts $message

This will output the value of the $message global variable, which is "Hello, world!".

That's it! You have successfully accessed a global property in Ruby.

[[SOURCE #7]]