--nextPart1298970.LlIXkWMVDK
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Quoth Clifford Heath:
> Folk,
>=20
> I found Sean Russell's 2001 posting on this subject, and had a play with=
=20
creating
> open ranges using of class instances - interesting to find you can even d=
o=20
this!
>=20
> What I really want is to be able to define ranges like (1..nil), which is=
 an
> open-ended range starting from 1. Of course this doesn't work, but not fo=
r=20
the
> reason I expected. There seems to be some magic inside MRI that prevents =
it.
>=20
> Like if I define:
>=20
> class End
> 	attr_reader :e
> 	def initialize(e)
> 		@e =3D e
> 	end
> 	def <=3D>(other)
> 		@e <=3D> other.e
> 	end
> 	def succ
> 		@e && @e.succ
> 	end
> end
>=20
> Then I can create the following range: End.new(1) .. End.new(4)
> but not this: End.new(1) .. End.new(nil)
>=20
> Ok, perhaps that's fair enough. But inside class End, replace all
> references to @e by @e.to_i (just for the experiment), and it works
> (at least, it bitches that 0 is less than 1, but use
> End.new(-1) .. End.new(nil)
> and it's ok).
>=20
> Now add puts "#{@e.to_i} <=3D> #{other.e}"; into the "<=3D>" method, and
> Range "knows" that's not ok... when to my mind it should be ok if the
> previous version was.
>=20
> I haven't taken this any further yet. Until I know that some internal
> magic isn't going to stop me making a Range class that works as advertise=
d,
> it didn't seem worth pursuing.
>=20
> What do you think?
>=20
> Clifford Heath.

=46ixnum#<=3D> doesn't like that you're passing nil to it (I think). So you=
 need=20
to fix your End#<=3D> definition to only use Fixnum's spaceship operator if=
 the=20
other end is also a Fixnum. If it's a nilclass, always return whatever woul=
d=20
make the range go on forever :).

Regards,
=2D-=20
Konrad Meyer <konrad / tylerc.org> http://konrad.sobertillnoon.com/

--nextPart1298970.LlIXkWMVDK
Content-Type: application/pgp-signature; name=signature.asc 
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHQOYoCHB0oCiR2cwRAmkLAJ9Q5X9rw0avG4g98VKeNxYcup+gyACgzQ5T
nSybTa42/oemZSeQyIi+kEQ=
=DXKa
-----END PGP SIGNATURE-----

--nextPart1298970.LlIXkWMVDK--