Class: Array
- Defined in:
- lib/ruby_smart/support/core_ext/ruby/array.rb,
lib/ruby_smart/support/core_ext/ruby/array.rb
Instance Method Summary collapse
-
#only(*values) ⇒ Array
returns a new array with only given values (if exists).
-
#only!(*values) ⇒ Array
refactors the same array with only given values (if exists).
Instance Method Details
#only(*values) ⇒ Array
returns a new array with only given values (if exists)
32 33 34 |
# File 'lib/ruby_smart/support/core_ext/ruby/array.rb', line 32 def only(*values) dup.only!(*values) end |
#only!(*values) ⇒ Array
refactors the same array with only given values (if exists)
14 15 16 17 |
# File 'lib/ruby_smart/support/core_ext/ruby/array.rb', line 14 def only!(*values) reject! { |value| !values.include?(value) } self end |