Last active
August 29, 2015 14:01
-
-
Save bastosmichael/a701f8ada44b19315a45 to your computer and use it in GitHub Desktop.
mass object assignment without an array or enumerable
This file contains hidden or 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 Xs # represent a string of 'x's | |
include Comparable | |
attr :length | |
def initialize(n) | |
@length = n | |
end | |
def succ | |
Xs.new(@length + 1) | |
end | |
def <=>(other) | |
@length <=> other.length | |
end | |
def to_s | |
sprintf "%2d #{inspect}", @length | |
end | |
def inspect | |
'x' * @length | |
end | |
end | |
r = Xs.new(3)..Xs.new(6) #=> xxx..xxxxxx | |
r.to_a #=> [xxx, xxxx, xxxxx, xxxxxx] | |
r.member?(Xs.new(5)) #=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment