[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Help extending Hash to allow hexadecimal encoded keys (problem with "Delegator"

Sean O'Halpin

5/23/2008 1:08:00 PM

On Fri, May 23, 2008 at 11:21 AM, I=F1aki Baz Castillo <ibc@aliax.net> wrot=
e:
> 2008/5/23, Heesob Park <phasis@gmail.com>:
>
>> def []=3D(k,v)
>> k =3D CiString.new(k) if String =3D=3D=3D k
>> __getobj__[k] =3D v
>> end
>>
>> def [](k)
>> k =3D CiString.new(k) if String =3D=3D=3D k
>>
>> __getobj__[k]
>> end
>>
>> def find(ifnone =3D nil,&blk)
>> __getobj__.find(ifnone,&blk)
>> end
>>
>> def find_all(&blk)
>> __getobj__.find_all(&blk)
>> end
>
>
>
> Thanks a lot, but it gives me errors:
>
> @uri
> =3D> {"T%61g"=3D>"%61liCE", "qwe"=3D>"qqqqqqqqqqQQQQQQQQQQQ"}
>
> @uri.find {|e| e[0] =3D=3D "qwe" }
> NoMethodError: undefined method `string' for "qwe":String
> from uri.rb:72:in `=3D=3D'
> from (irb):6
> from (irb):6:in `find'
> from uri.rb:98:in `each'
> from uri.rb:98:in `find'
> from uri.rb:98:in `find'
> from (irb):6
>
>
> Unfortunatelly I have no idea of how to debug it since I don't
> understand how exactly Delegator works. Any tip please?
>
> Really thanks a lot.
>
>
>
> --
> I=F1aki Baz Castillo
> <ibc@aliax.net>
>

I think you want something like:

def eql?(s)
unescape(string.downcase).eql? unescape(s.to_s.downcase)
end

with Park's changes so that:

uri =3D UriParametersHash.new
uri["T%61G"] =3D "lololo"
uri # =3D> {"T%61G"=3D>"lololo"}
uri.find{|e| e[0] =3D=3D "tag"} # =3D> ["T%61G", "lololo"]

Regards,
Sean