On Fri, May 30, 2014 at 8:12 PM, Arup Rakshit
<aruprakshit / rocketmail.com> wrote:

> Does it mean I can use String#% to hash only when Hash will have keys as a
> symbol ? Or there is a trick, that I am missing.

String#% does not hash - it's a shortcut for sprintf():

irB(mAin):008:0> "A%04dB" % 1
=> "A0001B"
irB(mAin):009:0> "A%04dB" % 34
=> "A0034B"
irB(mAin):010:0> "A%04dB%pX" % [34, 99]
=> "A0034B99X"
irB(mAin):011:0> "A%04dB%pX" % [34, [1,2]]
=> "A0034B[1, 2]X"

irb(main):012:0> sprintf "A%04dB", 1
=> "A0001B"
irb(main):013:0> sprintf "A%04dB", 34
=> "A0034B"
irb(main):014:0> sprintf "A%04dB%pX", 34, 99
=> "A0034B99X"
irb(main):015:0> sprintf "A%04dB%pX", 34, [1,2]
=> "A0034B[1, 2]X"


Cheers

robert

-- 
[guy, jim].each {|him| remember.him do |as, often| as.you_can - without end}
http://blog.rubybestpractices.com/