Skip to content

Instantly share code, notes, and snippets.

@havenwood havenwood/this_dude.rb

Last active Aug 15, 2018
Embed
What would you like to do?
A "fun" solution to this_dude's problem in the #ruby irc channel: http://www.codewars.com/kata/sum-of-digits-slash-digital-root/train/ruby
class Proc
def >> other
-> arg { other.to_proc.call call arg }
end
end
class Symbol
def >> other
to_proc >> other.to_proc
end
end
class Enumerator
class << self
def generate value
raise ArgumentError, 'No block given' unless block_given?
Enumerator.new Float::INFINITY do |yielder|
loop do
yielder << value
value = yield value
end
end
end
end
end
Enumerator.generate(942, &:digits >> :sum).find(&:digits >> :one?)
#=> 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.