Sometimes I don’t want to statically pick from a dataset or a hash. Sometimes I want to dynamically pick from a hash or dataset based on a condition and I can do that by using a beesting in a pick statement.
ruleset a60x545 {
meta {
name "beesting-in-pick"
description <<
beesting-in-pick
>>
author "Mike Grace"
logging on
}
rule test_pick {
select when pageview ".*"
pre {
r = math:random(2);
pleasePick = (r == 0) => "userName" | "cool";
myHash = {
"userName":"mike",
"cool":"yes"
};
picked = myHash.pick("$.#{pleasePick}");
}
{
notify("picked","Picked with: #{pleasePick}<br/>Picked value: #{picked}") with sticky = true;
}
}
}
- 14 get random number to simulate picking based on condition
- 15 set pick based on random based condition
- 20 get value from pick statement
App run several times in a row on example.com with a bookmarklet
Get the bookmarklet to try it out yourself!
Gratuitous day 34 Grace face


The more general idea here is that the pick specification is just a string and there are lots of ways to construct a string. Beestings are among the most convenient, but it’s also possible, as an example, to get the pick string from one hash and use it to pick on another.