From the documentation for String#count I understand the first example, but I do not understand the rest of the examples:
a = \"hello world\"
a.count \"lo\"
I'll take a stab:
Second example: using the wording "The intersection of these sets defines the characters to count in str" the parameters are "lo" and "o". The intersection of these is just "o" of which there are 2 in the string being counted on. Hence the return value of 2.
Third example: This one seems to be saying: "Any of the characters in 'hello' but not the character 'l'". Getting this from the line "Any other_str that starts with a caret (^) is negated". So, you can count the set of letters contained in the string "hello" which are found in "hello world" (i.e., h,e,l,l,o,o,l) but then comparing the intersection with the set of "^l"
(i.e. h,e,o,w,o,r,d) you are left with 4 (i.e. h,e,o,o).
Fourth example: This one basically says "count all the 'e' characters and any character between 'j' and 'm'. There is one 'e' and 3 characters contained between 'j' and 'm' and all 3 happen to be the letter 'l' which leaves us with an answer of 4 again.