We all know that you need to use the Configure--disable-pthread parameter when compiling ruby. Yes, configure--disable-pthread allows you to get about 30% performance improvements. But, what is this for?
All of this we need to use the Strace tool,
1 open and close a file
Class method File.new opens a file and instantiates it as a file object, and his first argument is the filename.
The optional second argument is called the mode string (which is also derived from c). He means to open a file
A real variable starts at the @, its scope is limited to the self object. Two different objects, even if they belong to the same class, can have real variables of different values. From outside the object, the real variable cannot be changed or even
Class method
The essence of a class method is a single piece method that lives in a single piece of the class. There are three ways to define them, respectively:
# method One
def Myclass.a_class_method end
# Two
class MyClass
def
Algorithm principle:
Compare the adjacent elements. If the first one is bigger than the second one, swap them both.Do the same work for each pair of adjacent elements, from the first pair to the end of the last couple. At this point, the final
In a file there are many of the following:
This topic selected D.
....
....
....
And I want to achieve the function is to replace it:
This topic selected D.
.....
.....
.....
This thing looks a little bit simple, but
A constant begins with a capital letter. It should be assigned up to one time. In the current version of Ruby, the re-assignment of constants produces only warnings rather than errors (the Non-ansi version of EVAL.RB does not report this
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
We know the top-level domain, what is the self of the domain defined?
Copy Code code as follows:
Puts self #main
Puts Self.class #Object
We know that when a method is invoked, if there is no object to accept, the default is
If you test the RESTful service by hand, it will be very tedious. Of course, there are some browser plug-ins that can help you manually test by using a visual interface, such as postman, rest console, but every time a system version is updated, you
The use of simple methods
There is a list of strings that need to be converted to uppercase for each of these strings, and we can do it in a simple notation.
Copy Code code as follows:
Name_list = ["Chareice", "Angel"]
In ActiveRecord, you can define the association between model in a convenient declarative way, for example:
Copy Code code as follows:
Class Topic Has_many:p OSTs
Belongs_to:user
End
Has_many and belongs_to are actually
1. String Object definition
The definition of a string object can use "and", for simple strings, it is recommended to use ' to define, ' the difference between efficiency and ' high, ' and ' is that ' the string defined in ' is the final form, even
Recently, there is a need to use a string as a class, for example:
There is a string "Chinamag" that invokes the method under the class Chinamag according to this string.
Solution:
1.rails You can use the Constantize method.
Copy Code code
If you want to see the source code for the ActiveRecord update_attribute function, a more common approach is to search for Def Update_attribute directly from the Rails source. Blog The Pragmatic Studio introduces a more convenient technique to
1. Use Ruby Eventmachine and Em-http-server gem to complete a simple httpserver to provide file download functionality
2. Using the Filestreamer of EM to send the file asynchronously, the header is assembled before the file is sent, and then the
Beginners Ruby, many need to learn, now start to try to write a script using Ruby, which uses a lot of file-related operations, here to organize some. Easy to find again later.
Whether a file or directory exists
Copy Code code as follows:
First, the preface
IronRuby is a ruby implementation in. NET, and ruby.net this Open-source project, the main difference is that IronRuby leverages Microsoft's newest DLR, while Ruby.net is fully leveraging the original CLR implementations.
Some difficulties in learning ruby language learning comprehension
The Ruby language is a relatively simple language because all of its design principles are object-oriented, so it's especially handy to use. Of course, the main reason is
Ruby saves the data queried by mysql to excel and rubymysql
Require "win32ole" require 'pathname' require 'mysql2' excel = WIN32OLE. new ('excel. application ') excel. visible = true # in case you want to see what happensclient = Mysql2: Client. new
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