Ruby defined operator
defined? operator
The defined? the operator is used to check whether or not the passed expression is defined. It returns nil if its argument is not defined, otherwise, it returns a descriptive string of that argument.
Syntax :
defined? expression
Here are some usage of defined? operator:
Example: Ruby defined operator
x = 1
Height = 100
puts ("defined operator in Ruby")
puts defined? x # "local-variable"
puts defined? 12 # "expression"
puts defined? y # nil
puts defined? puts # "method"
puts defined? Height # "constant"
puts defined? $& # nil
puts defined? $_ # "global-variable"
puts defined? Math::PI # "constant"
puts defined?( c = 22 ) # "assignment"
puts defined? 12.abs # "method"
Output:
defined operator in Ruby local-variable expression method constant global-variable constant assignment method
Previous:
Ruby Ternary operator
Next:
Ruby Dot And Double Colon Operators
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join