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\"
Let's break these down
a = "hello world"
to count the number of occurrences of the letters l
and o
a.count "lo" #=> 5
to find the intersect of lo
and o
(which is counting the number of occurrences of l
and o
and taking only the count of o
from the occurrences):
a.count "lo", "o" #=> 2
to count the number of occurrences of h
, e
, l
, l
and o
, then intersect with any that are not l
(which produces the same outcome to finding occurrences of h
, e
and o
)
a.count "hello", "^l" #=> 4
to count the number of occurrences of e
and any letter between j
and m
(j
, k
, l
and m
):
a.count "ej-m" #=> 4