In Ruby, everything is an object. More precisely, everything in Ruby is a fully functional object. So, in Ruby, the number 4, the fixed-point number 3.14, and the string "Hi" are all objects. Obviously, they are a bit "special" because you don't
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,
Metaprogramming is not a very new concept, usually metaprogramming is considered to be a program to generate the program, if from this point of view, then Lex and YACC and JAVACC should all be considered to have the concept of metaprogramming, in
Everything in Ruby is an object. Even a block of code is an Object! In Ruby, a code object is called a block of code. You can imagine a code block as a small program unit. They contain Ruby code and can be transferred to the method when they are
Ruby,nokogori, crawl through the latest 10 pages plus picture ratio and save it both in text and database
Copy Code code as follows:
#encoding: Utf-8
Require "Open-uri"
Require "Nokogiri"
Require "MySQL"
@dbh =mysql.real_connect
send message to object display
We can send a message directly to the object:
Ruby Code
Copy Code code as follows:
Class HelloWorld
def say (name)
Print "Hello,", name
End
End
HW = Helloworld.new
Hw.send (: Say, "world")
N+1 problem
The n+1 problem is one of the most common performance issues in database access, and first describes what a n+1 problem is:
For example, we have two tables in our database, one is customers, and the other is orders. The orders contains
1. How to declare a subclass
Copy Code code as follows:
Class Treasure
So the property name,description in the thing class are treasure inherited
2. What are the parameters of the Initialize method passed into the parent class
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
Recently playing Ruby, good to say, very feeling; OpenSUSE 12.3 on an old machine and then using RVM to install Ruby, in fact, any good release package Ruby is better than using RVM installed Ruby, personally feel (defy).
Then, when you install
Ruby gives us six ways to complete a task when we encounter the need to invoke the operating system shell command:
1.Exec Method:
The Kernel#exec method replaces the current process example by invoking the specified command:
Copy Code code
I wrote a Ruby plug-in with C + + swig in my early years, but in practice I wrote Ruby extensions in native C + + because it was fairly simple. But long useless or will forget, had to turn over the old code memories, write this blog, if the next
Exceptions and executions are always linked together. If you open a file that does not exist and you do not properly handle the situation, your program is considered to be of low quality.
If an exception occurs, the program stops. Exceptions are
In the last section, we added error handling to the shopping cart, this time to format the empty cart and amount.
To this moment we have not added any processing to the "Empty cart" link that displays the Shopping information list page. We first
Writing a database management system with Ruby on Rails is very fast. Ruby on Rails has such a high productivity, not only is Ruby's syntax flexible, but it's all a big program thanks to activity records (active record). So what is an activity
For several days, ROR environment finally set up, in order to prevent later forget, less detours, special records
=============================================
installation process
1. Installation rubyinstaller-1.9.2
2, install the
First, max_by,min_by the minimum value of the maximum value in the array according to the condition1 " This is a string " 2 arr = Str.split ("")3#"a"4# "string"Second, find finds the first element of a match1 " This is a string " 2 arr = Str.split (
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