As already suggested you can utilise digits
. Used with reduce
you can write something like this:
number.select { |n| n.digits.reduce(0) { |m, n| m + n**3 } == n }
#=> [153, 370]
More Related Contents:
- How to convert Time format in ruby
- /^a-eg-h/.match(‘f’) gives null in Ruby
- How to call methods dynamically based on their name? [duplicate]
- What’s the difference between equal?, eql?, ===, and ==?
- How to find and return a duplicate value in array
- Executing code for every method call in a Ruby module
- No increment operator (++) in Ruby? [duplicate]
- Debugging in ruby 1.9
- Is Hash Rocket deprecated?
- Using Sinatra for larger projects via multiple files
- How to split (chunk) a Ruby array into parts of X elements? [duplicate]
- Understanding [ClassOne, ClassTwo].each(&:my_method) [duplicate]
- ActionController::UnknownFormat
- Sort hash by key, return hash in Ruby
- How to merge Ruby hashes
- I don’t understand ruby local scope
- Strange \n in base64 encoded string in Ruby
- Double Pipe Symbols in Ruby Variable Assignment? [duplicate]
- How can I clear the terminal in Ruby?
- How do I avoid trailing empty items being removed when splitting strings?
- How do I test a function with gets.chomp in it?
- How to create directories recursively in ruby?
- Logging in Sinatra?
- Running a Ruby Program as a Windows Service?
- what does @ stand for in a Ruby function name
- How to get class instances in Ruby? [duplicate]
- Ruby Definition of Self
- Transliteration in ruby
- In Ruby, why does nil[1]=1 evaluate to nil?
- How to match something with regex that is not between two special characters?