Why is the true output for this operator in ruby?

I called the following statements in the range triples = "AAA".."ZZZ":

  • triples.include? "ABC" # => true: slow in ruby 1.9 and fast in ruby 1.8

    I understood why the conclusion true, but could not understand why it works fast in ruby โ€‹โ€‹1.8 and slower in ruby โ€‹โ€‹1.9.

  • triples.include? "ABCD" # => false: ruby 1.9 and true: ruby 1.8

    I could not understand why the output in both versions is different.

  • triples.cover? "ABCD" # => true and fast in ruby 1.9

    Same problem as the second operator.

Why operators cover?and include?differ from each other in ruby 1.9?

+4
source share
2 answers

In Ruby> = 1.9, include?iterates through each element in a range and checks to see if a given element is present.

cover? , >= , <= .

- , Ruby () "ABCD" > "AAA" "ABCD" < "ZZZ".

Ruby 1.8, include? Ruby 1.9 cover?.

, , .

, , , (0..1_000_000_000).cover?(1_000_000_001) , include? - .

, include?: "ABCD" ("AAA".."ZZZ"), .

+4

Ruby 1.9 include? true, .

, include? - cover?:

r = 1..10
r.include?(5) # => true
r.include?(5.5) # => true

# ?

true, obj , false . begin end , .

+1

All Articles