Ruby Basic data types

Source: Internet
Author: User

#numbers are classified as certificate integer, floating-point number float (corresponding to double in other languages), and plural complex#integers are divided into fixnum and Bignum,fixnum and Bignum to each other, and these are the operations that Ruby automatically manages. a=123_333_3432#Adding an underscore does not affect the value of a numberputs Aputs 0b00000010#0b is a binaryPuts 0123#0 is octalPuts 0xa0#hexadecimalPuts 2<=>2#the former larger than the latter returns 1, equals returns 0, smaller than the latter returns-1#floating point float#String strings usually use single or double quotation marksStr='1233DD'Str="1233ff"#Sometimes you need to construct a very long and contain a lot of single quotes, double quotes, so it is more cumbersome#Ruby also provides string notation such as%,%q and%q, which need to be followed by a bunch of delimiters to contain strings (<>,{},[] and so on), here for large segments of text using << start, plus start and end identities str=%{"FDSF '"Dsf"}str=%q{"FDSF '"Dsf"}str=%q{"FDSF '"Dsf"}str=<<H Sdfsdfsdgasgsaldfjsaldfkjas;dlfkja;sdlkfjlsdfsadfsadfsdfasdfah#An embedded string is a method that checks a string form of a variable into another string using the format # (VAL), and if Val is not a string type, the To_s method of Val is called before the implicit conversion, and then the inlineName="Ma Huan"puts"my name is #{name}"#<< the same effect as the + operation. Attaches the given object to the string object, generating a new object. str<<"the new haha"puts Str.include? ("haha")#symbol type, a string of the same content may be two different objects, and the symbol represented by the same identifier refers to the same instance from anywhere, pointing to the same reference. #symbols are compared with strings and consume less memory. A="Str"b="Str"puts a.object_id==B.OBJECT_IDSA=: STRSB=: strputs sa.object_id==sb.object_id

Ruby Basic data types

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.