1 Using multiple construction methods
There are no constructors in Ruby like C + + or Ruby, but we can still create a similar number of constructors:
Ruby Code
Class Coloredrectangle
def initialize (R, G, B, S1, S2) @r, @g,
@b, @s1, @s2 = R, G,
You create an array by listing the elements in square brackets and separating them from each other by commas. The array of Ruby can accommodate different object types
ruby> ary = [1, 2, "3"]
[1, 2, "3"]
Just like the string mentioned earlier.
1. Read-write properties of member variables: Attr_reader and Attr_writer class Test
Def initialize (name)
@name = name
end
attr_reader:name
attr_writer:name end
test = Test.new ("AAA")
puts test.name
test.name = "BBB"
puts Test.name
If
First, in ruby1.8, class variables are shared by all subclasses and parent classes, and you can look at the following code:
class IntelligentLife @@home_planet = nil def self.home_planet @@home_planet end def self.home_planet=(x)
This article mainly introduces the example of Ruby optimization inheritance class, this article directly gives an example of optimization and implementation code, the need for friends can refer to the following
In the rails principle there is the
Hook methods are similar to event-driven devices that can perform a specific callback function after a particular event occurs, which is the hook method (more descriptive: The hook method can hook a particular event like a hook). , the Before\after
Open Class
You can reopen a class that already exists and modify it dynamically, even if the class of a standard library like string or array is no exception. This behavior is called Open class
Monkey Patch
If you inadvertently add new
Language-related settings and strings should not be used in views, models, and controllers. These words should be moved to a language file under the Config/locales.
When the label of the ActiveRecord model needs to be translated, use the
%q
A string that replaces double quotes. When you need to put a lot of quotes in a string, you can use the following method directly without adding a backslash (\) to the quotation mark.
Copy Code code as follows:
>>%q (Joe said:
Requirements for: input points from the keyboard, in order to judge, 0-59 for the failure, print "You did not pass, please try next time!", 60-79 for passing, print "Your grades pass, please work harder!" ", 80-100 for good results, print" Your
Divided into the following sections:• Basic implementation• Reference the original object in the iteration, or change the value of the array directly instead of returning a new array• Pass an infinite number of arguments to the iteration• Basic
Since you are ready to use bootstrap in your project, you will be prompted for a ruby version at 1.9.2 during the installation of Bootstrap, while the Ruby version that is currently in use is the 1.8.7 that comes with the Mac system. So you need to
1, download the latest version of Rubyinstaller and install http://rubyinstaller.org/downloads/Set the path as shown, and I'll have enough of all the options when I install, eliminating the need for any later configuration hassles.2, after the
1. Logical operators(1) Condition 1 | | Condition 2Condition 1 is false , only need to judge condition 2(2) Conditions 1 && conditions 2Condition 1 is true , the condition must be judged 22. Range operator(1) x.. Y from X to Y, including y(2) X...y
Statement: This article is not an article about nodejs and Ruby on Rails. It only describes the reasons behind the thinking and decision-making in our decision-making process. The two frameworks are both excellent and both of them are well designed.
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