From: Michael Fellinger on
On Sat, Jun 19, 2010 at 3:43 AM, Josh Cheek <josh.cheek(a)gmail.com> wrote:
> On Fri, Jun 18, 2010 at 12:46 PM, Abder-rahman Ali <
> abder.rahman.ali(a)gmail.com> wrote:
>
>> When I try for example to compare the following strings in Ruby, I get
>> "true".
>>
>> puts 'Xeo' < 'ball'
>>
>> When I make 'Xeo' start with a lowercase letter, i get 'false'
>>
>> puts 'xeo' < 'ball'
>>
>> The second statement is clear, but why when I capitalize 'Xeo' I get
>> true?
>>
>> Thanks.
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
> Well, this used to be easy to show, but apparently since ascii has been
> abandoned, and I don't know unicode, I have to resort to hacky things like
> this to explain it.
>
>
> $chars = (1..128).inject(Hash.new) { |chars,num| chars[num.chr] = num ;
> chars }
>
> def to_number_array(str)
>  str.split(//).map { |char| $chars[char] }
> end
>
> to_number_array 'Xeo'   # => [88, 101, 111]
> to_number_array 'xeo'   # => [120, 101, 111]
> to_number_array 'ball'  # => [98, 97, 108, 108]
> to_number_array 'ABC'   # => [65, 66, 67]
> to_number_array 'abc'   # => [97, 98, 99]

>> %w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.codepoints.to_a }
{"ABC"=>[65, 66, 67]}
{"Xeo"=>[88, 101, 111]}
{"abc"=>[97, 98, 99]}
{"ball"=>[98, 97, 108, 108]}
{"xeo"=>[120, 101, 111]}
=> ["ABC", "Xeo", "abc", "ball", "xeo"]


--
Michael Fellinger
CTO, The Rubyists, LLC

From: Xeno Campanoli / Eskimo North and Gmail on
On 10-06-18 02:09 PM, Michael Fellinger wrote:
> On Sat, Jun 19, 2010 at 3:43 AM, Josh Cheek<josh.cheek(a)gmail.com> wrote:
>> On Fri, Jun 18, 2010 at 12:46 PM, Abder-rahman Ali<
>> abder.rahman.ali(a)gmail.com> wrote:
>>
>>> When I try for example to compare the following strings in Ruby, I get
>>> "true".
>>>
>>> puts 'Xeo'< 'ball'
>>>
>>> When I make 'Xeo' start with a lowercase letter, i get 'false'
>>>
>>> puts 'xeo'< 'ball'
>>>
>>> The second statement is clear, but why when I capitalize 'Xeo' I get
>>> true?

That's an artifact of the old ASCII encoding. Uppercase letters came out first
so they have a lower integer value than uppercase.
>>>
>>> Thanks.
>>> --
>>> Posted via http://www.ruby-forum.com/.
>>>
>>>
>> Well, this used to be easy to show, but apparently since ascii has been
>> abandoned, and I don't know unicode, I have to resort to hacky things like
>> this to explain it.
>>
>>
>> $chars = (1..128).inject(Hash.new) { |chars,num| chars[num.chr] = num ;
>> chars }
>>
>> def to_number_array(str)
>> str.split(//).map { |char| $chars[char] }
>> end
>>
>> to_number_array 'Xeo' # => [88, 101, 111]
>> to_number_array 'xeo' # => [120, 101, 111]
>> to_number_array 'ball' # => [98, 97, 108, 108]
>> to_number_array 'ABC' # => [65, 66, 67]
>> to_number_array 'abc' # => [97, 98, 99]
>
>>> %w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.codepoints.to_a }
> {"ABC"=>[65, 66, 67]}
> {"Xeo"=>[88, 101, 111]}
> {"abc"=>[97, 98, 99]}
> {"ball"=>[98, 97, 108, 108]}
> {"xeo"=>[120, 101, 111]}
> => ["ABC", "Xeo", "abc", "ball", "xeo"]
>
>


--
"It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Fri, Jun 18, 2010 at 4:09 PM, Michael Fellinger <m.fellinger(a)gmail.com>wrote:

> On Sat, Jun 19, 2010 at 3:43 AM, Josh Cheek <josh.cheek(a)gmail.com> wrote:
> > On Fri, Jun 18, 2010 at 12:46 PM, Abder-rahman Ali <
> > abder.rahman.ali(a)gmail.com> wrote:
> >
> >> When I try for example to compare the following strings in Ruby, I get
> >> "true".
> >>
> >> puts 'Xeo' < 'ball'
> >>
> >> When I make 'Xeo' start with a lowercase letter, i get 'false'
> >>
> >> puts 'xeo' < 'ball'
> >>
> >> The second statement is clear, but why when I capitalize 'Xeo' I get
> >> true?
> >>
> >> Thanks.
> >> --
> >> Posted via http://www.ruby-forum.com/.
> >>
> >>
> > Well, this used to be easy to show, but apparently since ascii has been
> > abandoned, and I don't know unicode, I have to resort to hacky things
> like
> > this to explain it.
> >
> >
> > $chars = (1..128).inject(Hash.new) { |chars,num| chars[num.chr] = num ;
> > chars }
> >
> > def to_number_array(str)
> > str.split(//).map { |char| $chars[char] }
> > end
> >
> > to_number_array 'Xeo' # => [88, 101, 111]
> > to_number_array 'xeo' # => [120, 101, 111]
> > to_number_array 'ball' # => [98, 97, 108, 108]
> > to_number_array 'ABC' # => [65, 66, 67]
> > to_number_array 'abc' # => [97, 98, 99]
>
> >> %w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.codepoints.to_a
> }
> {"ABC"=>[65, 66, 67]}
> {"Xeo"=>[88, 101, 111]}
> {"abc"=>[97, 98, 99]}
> {"ball"=>[98, 97, 108, 108]}
> {"xeo"=>[120, 101, 111]}
> => ["ABC", "Xeo", "abc", "ball", "xeo"]
>
>
> --
> Michael Fellinger
> CTO, The Rubyists, LLC
>
>

Thanks, but it doesn't seem to work on 1.8


RUBY_VERSION # => "1.8.7"

%w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.codepoints.to_a } #
=>
# ~> -:3: undefined method `codepoints' for "ABC":String (NoMethodError)
# ~> from -:3:in `each'
# ~> from -:3




And the 1.8 ways to get it don't work on 1.9 (ie "a"[0])

From: Xeno Campanoli / Eskimo North and Gmail on
On 10-06-18 02:21 PM, Josh Cheek wrote:
> On Fri, Jun 18, 2010 at 4:09 PM, Michael Fellinger<m.fellinger(a)gmail.com>wrote:

I thought Unicode started with ASCII anyway, so I don't think that solves it...

Yes, here:

http://www.tamasoft.co.jp/en/general-info/unicode.html
>
>> On Sat, Jun 19, 2010 at 3:43 AM, Josh Cheek<josh.cheek(a)gmail.com> wrote:
>>> On Fri, Jun 18, 2010 at 12:46 PM, Abder-rahman Ali<
>>> abder.rahman.ali(a)gmail.com> wrote:
>>>
>>>> When I try for example to compare the following strings in Ruby, I get
>>>> "true".
>>>>
>>>> puts 'Xeo'< 'ball'
>>>>
>>>> When I make 'Xeo' start with a lowercase letter, i get 'false'
>>>>
>>>> puts 'xeo'< 'ball'
>>>>
>>>> The second statement is clear, but why when I capitalize 'Xeo' I get
>>>> true?
>>>>
>>>> Thanks.
>>>> --
>>>> Posted via http://www.ruby-forum.com/.
>>>>
>>>>
>>> Well, this used to be easy to show, but apparently since ascii has been
>>> abandoned, and I don't know unicode, I have to resort to hacky things
>> like
>>> this to explain it.
>>>
>>>
>>> $chars = (1..128).inject(Hash.new) { |chars,num| chars[num.chr] = num ;
>>> chars }
>>>
>>> def to_number_array(str)
>>> str.split(//).map { |char| $chars[char] }
>>> end
>>>
>>> to_number_array 'Xeo' # => [88, 101, 111]
>>> to_number_array 'xeo' # => [120, 101, 111]
>>> to_number_array 'ball' # => [98, 97, 108, 108]
>>> to_number_array 'ABC' # => [65, 66, 67]
>>> to_number_array 'abc' # => [97, 98, 99]
>>
>>>> %w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.codepoints.to_a
>> }
>> {"ABC"=>[65, 66, 67]}
>> {"Xeo"=>[88, 101, 111]}
>> {"abc"=>[97, 98, 99]}
>> {"ball"=>[98, 97, 108, 108]}
>> {"xeo"=>[120, 101, 111]}
>> => ["ABC", "Xeo", "abc", "ball", "xeo"]
>>
>>
>> --
>> Michael Fellinger
>> CTO, The Rubyists, LLC
>>
>>
>
> Thanks, but it doesn't seem to work on 1.8
>
>
> RUBY_VERSION # => "1.8.7"
>
> %w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.codepoints.to_a } #
> =>
> # ~> -:3: undefined method `codepoints' for "ABC":String (NoMethodError)
> # ~> from -:3:in `each'
> # ~> from -:3
>
>
>
>
> And the 1.8 ways to get it don't work on 1.9 (ie "a"[0])
>


--
"It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

From: Michael Fellinger on
On Sat, Jun 19, 2010 at 6:21 AM, Josh Cheek <josh.cheek(a)gmail.com> wrote:
>
> Thanks, but it doesn't seem to work on 1.8
>
>
> RUBY_VERSION # => "1.8.7"
>
> %w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.codepoints.to_a } #
> =>
> # ~> -:3: undefined method `codepoints' for "ABC":String (NoMethodError)
> # ~>     from -:3:in `each'
> # ~>     from -:3
>
>
>
>
> And the 1.8 ways to get it don't work on 1.9 (ie "a"[0])

>> %w[Xeo xeo ball ABC abc].sort.each{|word| p word => word.unpack('C*') }
{"ABC"=>[65, 66, 67]}
{"Xeo"=>[88, 101, 111]}
{"abc"=>[97, 98, 99]}
{"ball"=>[98, 97, 108, 108]}
{"xeo"=>[120, 101, 111]}
=> ["ABC", "Xeo", "abc", "ball", "xeo"]

There is always a way to make things work on both, it's just that I
don't care much about 1.8 anymore.

--
Michael Fellinger
CTO, The Rubyists, LLC