Open In App
Related Articles

Ruby | Array class frozen?() operation

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
Array#frozen?() : frozen?() is a Array class method which checks whether the array is frozen (or temporarily frozen while being sorted)
Syntax: Array.frozen?() Parameter: Array to check Return: true – if array is frozen; otherwise false
Code #1 : Example for frozen?() method
# Ruby code for frozen?() method
  
# declaring array
a = [18, 22, 33, nil, 5, 6]
  
# declaring array
b = [1, 4, 1, 1, 88, 9]
  
# declaring array
c = [18, 22, nil, nil, 50, 6]
  
# frozen?
puts "frozen? : #{a.frozen?()}\n\n"
  
# frozen?
puts "frozen? : #{b.frozen?()}\n\n"
  
# frozen?
puts "frozen? : #{c.frozen?()}\n\n"

                    
Output :
frozen? : false

frozen? : false

frozen? : false
Code #2 : Example for frozen?() method
# Ruby code for frozen?() method
  
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
b = ["cow", nil, "dog"]
  
# declaring array
c = ["cat", nil, nil]
  
# frozen?
puts "frozen? : #{a.frozen?()}\n\n"
  
# frozen?
puts "frozen? : #{b.frozen?()}\n\n"
  
# frozen?
puts "frozen? : #{c.frozen?()}\n\n"

                    
Output :
frozen? : false

frozen? : false

frozen? : false


Last Updated : 08 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads