Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Array#clear

() -> self
clear → self

Removes all elements from self; returns self:

Example
a = [:foo, 'bar', 2]
a.clear # => []

Related: see Methods for Deleting.

See also #bsearch_index #collect #bsearch #collect! also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0