Forum: Ruby Re: string range membership

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
warrenbrown (Guest)
on 2005-11-23 16:58
(Received via mailing list)
Brian,

> I'd argue that it is not a bug, as there is no unique
> isomorphie from strings to integers.

    I have to disagree.

>ruby -v -e "p(('1'..'10').to_a)"
ruby 1.8.2 (2004-12-25) [i386-mswin32]
["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]

    This shows a clear and unique mapping of the range '1'..'10' into a
set of strings.

    - Warren B.
ara.t.howard (Guest)
on 2005-11-23 17:06
(Received via mailing list)
On Wed, 23 Nov 2005, Warren B. wrote:

>
>    This shows a clear and unique mapping of the range '1'..'10' into a
> set of strings.

but where do '01', '001', and '0001' go?  they too, are in the set of
strings.

regards.

-a
matz (Guest)
on 2005-11-23 17:18
(Received via mailing list)
Hi,

In message "Re: [BUG] string range membership"
    on Wed, 23 Nov 2005 23:57:41 +0900, "Warren B."
<removed_email_address@domain.invalid> writes:

|> I'd argue that it is not a bug, as there is no unique
|> isomorphie from strings to integers.
|
|    I have to disagree.

For your information, member? used to iterate over items to check
membership.  But since confusion between include? and member?, they
were merged.  The point is Ranges are used both for ranges and
intervals.  Sometimes users want it to behave like a range surrounded
by begin/end values.  Sometimes they want it to behave like a set of
values, that #each produces.

I'd like to care this issue, but I haven't know the right way to solve
it yet.  Perhaps we should provide both membership method, with right
names for each.  Any ideas?

							matz.
ruby.brian (Guest)
on 2005-11-23 17:30
(Received via mailing list)
On 23/11/05, Warren B. <removed_email_address@domain.invalid> wrote:
>
>     This shows a clear and unique mapping of the range '1'..'10' into a
> set of strings.
>
>     - Warren B.
>

It is not unique as

ruby -e "p %w(1 10 11 100 101).map { | b | b.to_i(2) }"
[1, 2, 3, 4, 5]

is another mapping of strings to integers that is equally valid (and
would not contain '5').

Brian


--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/
This topic is locked and can not be replied to.