Summary of several common Ruby core concepts

Source: Internet
Author: User

Classes and objects in Ruby are important knowledge points. To learn the Ruby language, you must first master the application of Ruby objects and classes. Here we will learn about the Ruby core class.

  • Ruby blocks provides flexible encoding methods
  • Parse Json IN Ruby
  • Ruby module Win32API calls win32API directly
  • How to call win32ole IN Ruby
  • Ruby basic code Experience Sharing

Ruby core Class 1, Array

1. instantiation

1) Array. new

2) [value 1, value 2, value 3, value 4, value 5]

3) % w [red green blue balck] automatically converts the string list into an array, saving quotation marks and commas.

2. Method

1) empty? Returns true or false.

2) size returned size

3) first returns the first

4) last returns the last one.

5) delete "element" to delete

3. Tip: view the class help input command ri class name example ri Array

Ruby core Class II. Hash: save key-value pairs

1. instantiation

1) Hash. new

2) {key => value, key => value}

2. Method

1) empty?

2) size

3) keys: returns all keys.

4) values returns all values.

Ruby core Class 3, String: single quotation marks or double quotation marks

1. To include special characters such as quotation marks in a string, escape them"

2. Shortcut: % Q (string) Example: % Q (Arnie said, "I'm back !" )

3. the Ruby expression # {expression} can be embedded in the string. For example, "Current Time: # {Time. now }"

Note that only double quotation marks are supported. single quotation marks output the expressions as they are.

4. Method

Gsub (value 1, value 2), replace value 1 in the string with value 2
Include? (Value) include?
Slice () Interception

Ruby core Class 4: Numeric: Float Fixnum Bignum

1. 123. integer? Integer or not

2. 12.3.round rounding

3. 8. zero? 0 or not

4. 12. Convert to_f to Float

5. Convert 11.3.to _ I to Fixnum.

Ruby core Class 5, Symbol

1. It is equivalent to a string, but there is no method

2. Mutual Conversion

"Fox". to_sym
: Fox. to_s

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.