packing booleans

J

Joel VanderWerf

Does anyone else think it would be nice to be able to pack/unpack
booleans? Maybe like this...

[[true, false, true]].pack("y3") # ==> "\005"

I just chose 'y' because it's not used (as are [jokrt]), and it suggests
"yes", a boolean answer.
 
R

Robert Klemme

Joel VanderWerf said:
Does anyone else think it would be nice to be able to pack/unpack
booleans? Maybe like this...

[[true, false, true]].pack("y3") # ==> "\005"

I just chose 'y' because it's not used (as are [jokrt]), and it suggests
"yes", a boolean answer.

irb(main):015:0> a=[true, false,true]
=> [true, false, true]
irb(main):016:0> [a.inject(0){|acc,x| acc<<=1; acc|(x ?1:0)}].pack "I"
=> "\005\000\000\000"

Not exactly what you were asking for though - and it doesn't work with
Bignums...

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top