On Tue, Aug 13, Lukas Ocilka wrote:
On 08/13/2013 01:30 PM, Thomas Fehr wrote:
Hi,
While I was just fixing a bug in current head and had to test the fix anyway I assumed I could easily modify the ruby code needing to be adapted anyway to a more ruby-like style.
I replaced the common usage of hash access with default parameter by
YCP Code --> Ruby like replacement part["fsid"]:0 --> (part["fsid"]||0) part["type"]:`none --> (part["type"]||:none)
This might cause a buggy behavior if the value was /false/ !
part["format"] = false part.fetch("format", true) --> returns false part["format"] || true --> returns true
I see, thanks for mentioning this. So the above construct works for every type except bool. Neverthless I rewrote it using method fetch (that so far I did not know)
I've found some nice article on this: http://www.dotnetguy.co.uk/post/2012/08/19/ruby-hash-fetch-returning-a-value...
Nice to see others did not know about fetch too ;-)
I haven't checked that but you can access string as it was an array, so it seems this might work well.
irb(main):001:0> a = "12345678901234567890" => "12345678901234567890" irb(main):002:0> a[0,9] => "123456789" irb(main):003:0> a[0,2] => "12" irb(main):004:0> a[2,4] => "3456"
Looks good.
Meanwhile I have found string method starts_with? which should be more self explanatory for this special case. Tschuess, Thomas Fehr -- Thomas Fehr, SuSE Linux Products GmbH, Maxfeldstr. 5, 90409 Nuernberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Tel: +49-911-74053-0, Fax: +49-911-74053-482, Email: fehr@suse.de GPG public key available. -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org