Conditional operators in ruby

Source: Internet
Author: User
1. = (equal to) and! = (Not equal)

Returns true and flase if the values of the two objects are equal.

A = 1; B = 1.0; A = B # True

2. eql?

Returns true and flase if the values and types of the two objects are equal.

A = 1; B = 1.0; A. eql? (B) # flase (A is an integer and B is a floating point)

3. Equal?

Returns true and flase if two objects have the same address in the memory.
A = 1.0; B = 1.0; A. Equal? (B) # flase

A = 1.0; B = A; A. Equal? (B) # True

4. <=>

Compare the sizes of two objects. If the values are greater than, equal to, or less than, 1, 0,-1 are returned.
"AAB" <=> "ACB" #-1 (the ASCII code of the second A is less than C)

[5] <=> [4, 9] #1 (first element 5> 4)

5. =

Returns true and flase if the object on the right is within the left range.
Puts (0 .. 9) === 3.14 # True

Puts ('A' .. 'F') = 'C' # True

6. = ~ (Matching)

Used to compare whether a regular expression is met. The return mode is the position matched in the string. Otherwise, Nil is returned.

7 .!~ (Mismatch)

Returns true, flase

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.