Created
July 8, 2013 15:40
-
-
Save kouba-c/5949945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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