jiggery-pokery with switch/case and %W
Courtenay : December 20th, 2005
OK, here's a silly way of getting a little closer to Ruby's way of thinking with javascript. Maybe someone's already done this (flgr..?) but I'm putting this puppy up for adoption anyway.
First up, we have %W operator.
irb> %W' one two three '
=> ['one','two','three']
javascript> function $W(str) { return $A(str.split(/\s+/)); }
then, case
ruby:
case foo:
when 1,2,3:
# stuff
when 'four','five','six':
else:
# other stuff
end
javascript:
function stuff(arg) {
switch(true) {
case ($W('one two three').include(arg)):
stuff;
break;
case ($W('four five six').include(arg)):
other stuff;
break;
default:
break;
}
}
Wow, this is incredibly haphazard. Hope it /(helps|confuses)/ someone.
3 Responses to “jiggery-pokery with switch/case and %W”
Leave a Reply
Remember: escape your underscores \_ and indent code at least 4 spaces or incur the wrath of smartypants.
December 21st, 2005 at 03:25 AM you may have already seen this, but along similar lines: http://www.openjsan.org/src/f/fl/flgr/ruby.js/lib/ruby.js
July 31st, 2007 at 06:10 AM
Hello! Good Site! Thanks you! zgzrloxqcsrs
July 31st, 2007 at 07:33 AM
Thanks for this site! su.rnhmw.cn sgk.scvez.cn rnepf.fqtpq.cn loh.xlerr.cn fdnx.qzuxl.cn vg.mlubj.cn pq.qsvmk.cn u.zfwek.cn ggb.punwg.cn wp.mywev.cn tyvqk.lqwtm.cn szboi.tsdva.cn q.afsyf.cn csket.sryqx.cn af.fizyn.cn njs.fbnqg.cn uz.omemg.cn bh.mywev.cn pdgby.tsdva.cn zc.zlhmj.cn