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\"
Each argument defines a set of characters. The intersection of those sets determines the overall set that count uses to compute a tally.
a = "hello world"
a.count "lo" # l o => 5
a.count "lo", "o" # o => 2
And ^ can be used for negation (all letters in hello, except l)
a.count "hello", "^l" # h e o => 4
Ranges can be defined with -:
a.count "ej-m" # e j k l m => 4