Skip to content

Instantly share code, notes, and snippets.

@kouba-c
Created July 8, 2013 15:40
Show Gist options
  • Save kouba-c/5949945 to your computer and use it in GitHub Desktop.
Save kouba-c/5949945 to your computer and use it in GitHub Desktop.
class SuccProxy
attr_accessor :inner_obj, :succ_block
def initialize(a, &b)
@inner_obj = a
@succ_block = b
end
def succ
SuccProxy.new(@succ_block.call(@inner_obj), &@succ_block)
end
def <=>(o)
@inner_obj <=> o
end
include Comparable
end
hoge = SuccProxy.new(1){|x| x+=7}
(hoge..100).each do |i|
puts i.inner_obj
end
huga = SuccProxy.new('huga'){|x| x+=x}
(huga..'hugahugahugahuga').each do |s|
puts s.inner_obj
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment