How ’bout:
some_array.map {|x| x % 2 == 0 ? x * 3 : nil}.compact
Slightly cleaner, at least to my taste, and according to a quick benchmark test about 15% faster than your version…
More Related Contents:
- How to convert Time format in ruby
- Regex for reverse match a string
- Why do Ruby setters need “self.” qualification within the class?
- Ruby, Difference between exec, system and %x() or Backticks
- Why does Ruby 1.9.2 remove “.” from LOAD_PATH, and what’s the alternative?
- What is the difference or value of these block coding styles in Ruby?
- rvm installation not working: “RVM is not a function”
- How to understand symbols in Ruby
- Ruby array access 2 consecutive(chained) elements at a time
- What does &. (ampersand dot) mean in Ruby?
- How to count duplicate elements in a Ruby array
- Mixing keyword with regular arguments in Ruby?
- Should Gemfile.lock be included in .gitignore?
- Get names of all files from a folder with Ruby
- cannot load such file — zlib even after using rvm pkg install zlib
- Unresolved specs during Gem::Specification.reset:
- Extract a substring from a string in Ruby using a regular expression
- How to get rid of non-ascii characters in ruby
- How to convert a string to a constant in Ruby?
- What does the “||=” operand stand for in ruby [duplicate]
- Method to parse HTML document in Ruby?
- How do you uninstall rbenv on macOS?
- Really Cheap Command-Line Option Parsing in Ruby
- Running another ruby script from a ruby script
- ruby: class instance variables vs instance variables
- How to check if a directory/file/symlink exists with one command in Ruby
- Split string by multiple delimiters
- RVM and thin, root vs. local user
- Ruby array subtraction without removing items more than once
- How do I remove blank elements from an array?