RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

New gem 'multiples'!

When you want to step through all numbers that are divisible by either of two digits there is a palindrome pattern in that sequence (much like the patterns in frequencies that overlap). This gem discovers that palindrome and creates a custom enumerator like object that lets you step through each of those numbers. danielpclark/multiples

This may help save you some time by not looping over non-multiples when iterating through any range of numbers.


require "multiples"
x = Multiples.new(3,5)

x.lazy.take(4).to_a
# => [3, 5, 6, 9] 
x.next
# => 10 
x.prev
# => 9 

x.lazy.select {|v| v % 7 == 0 }.take(14).to_a
# => [21, 35, 42, 63, 70, 84, 105, 126, 140, 147, 168, 175, 189, 210]

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in