In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What is the common core class concept of Ruby? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Classes and objects in Ruby language is a very important knowledge point. To learn the Ruby language, the first thing to master is the use of Ruby objects and classes. Here we will learn about the introduction of Ruby core classes.
Ruby core class I, 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 list of strings into an array, omitting quotation marks and commas.
two。 Method
1) empty? Return true or false
2) size return size
3) first returns the first
4) last returns the last one
5) delete "element" deletion
3. Tip: view class help enter commands 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}
two。 Method
1) empty?
2) size
3) keys: return all key
4) values returns all value
Ruby core class 3. String: use single or double quotation marks
1. To include special symbols such as quotation marks in a string, you need to escape. "
two。 Shortcut:% Q (string) example:% Q (Arnie said, "Ihumm back!")
3. The Ruby expression # {expression} can be embedded in a string, for example: "current time: # {Time.now}"
Note that there can only be double quotation marks, and single quotation marks will output the expression as is
4. Method
Gsub (value 1, value 2), replacing the value 1 in the string with the value 2
Include? (value) whether it contains
Slice (0p3) intercept
Ruby core class IV. Numeric: Float Fixnum Bignum
1. 123.integer? Whether it is an integer
2. 12.3.round is rounded
3. 8.zero? Whether it is 0
4. Convert 12.to_f to Float
5. Convert 11.3.to_i to Fixnum
Ruby core class 5. Symbol symbol
1. Equivalent to a string, but there is no way
two。 Mutual conversion
"fox" .to _ sym
: fox.to_s
After reading the above, have you mastered the methods of what the common Ruby core class concepts are? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.