Open Class and Monkey patchesin Ruby, a class defines a method that does not differ from any other statement, and is executed on a line. The following example:
Class Example
def method_1
puts ' method 1 '
end
class Example
def
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
Instance_eval method
This basicobject#instance_eval is somewhat similar to the Bind method in JS, when bind is passed this into the object, and Instance_eval is the block of code (context probes Probe) Passed in to the specified object, one for the
In general, the definition of the observer pattern should be this: building a clean interface between the source of news that some object has changed and the Consumers O F that news.
The Observer pattern establishes a clean interface between the
Brief introductionA single case pattern is one of the simplest forms of design patterns. The purpose of this pattern is to make an object of a Class A unique instance of the system. To do this, you can start by instantiating it from the client.
Agent mode
Demand:
Xiaoming let Xiao Li Chase for him (send doll, send flowers, send chocolate)
Code with no agents:
#-*-Encoding:utf-8-*-
#追求者类
class Pursuit
attr_accessor:mm
def Initialize (mm)
@mm = mm
End
def give_dolls
Chinese garbled solutioncmd can not be entered in Chinese
Change the CMD code page to 936:
CHCP 936
Ruby read Chinese force set to Utf-8
You can add a comment statement to a file # Encoding:utf-8,ruby will be loaded in UTF-8 format
1. In proc and lambda, the return keyword has different meanings :In proc, return only means returning from this lambda.In a lambda, return is not returned from the proc, but rather from the scope in which the proc is defined.
Copy Code code
Require,load for files, such as. RB, and so on, at the end of the file. Include,load is used to include a module in a file.Require is typically used to load library files, while load is used to load configuration files.
1, require: load a library,
#建立一个222. rb file and enter the character file = File.Open ("222.rb", "w+") file.puts "123\NWADWA\N12124124\NDWDW" File.close #输出222. RB Content Fil
E.open ("222.rb", "r+") do |file|
While line = File.gets puts line end #直接用IO操作文件 Io.foreach
Ruby determines whether a number is primePrime numbers are also called primes. A natural number greater than 1, if it is not divisible by other natural numbers except for 1 and itself, (except for 0), otherwise known as composite numbers. According
And since Ruby is a completely pure object-oriented language, anything is an object, the method is an object, and the class is an object ..., so self has a lot of environments that distinguish the self meaning of different environments to better
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")
The PROFILE.RB is a profiler for Ruby programs that can count and output the elapsed time of each method in order to find performance bottlenecks in program execution. This time use it to dissect the running time of the script. Using the method is
Environment configuration
Before using Ruby to encode or decode JSON data, we need to install the Ruby JSON module first. Before installing the module you need to install Ruby Gem, and we use Ruby Gem to install the JSON module. However, if you are
Original address (outside the wall): https://medium.com/life-tips/ Should-you-learn-python-c-or-ruby-to-be-a-top-coder-infographic-188a5bdc9f54#.3ovedxuutTop programmers have unlimited prospects for employment, and even have the opportunity to
When your first started coding, errors were probably the last thing you wanted to see.After all, it's not a far stretch to associate "error" with "I messed up".Hopefully by now you've come to appreciate the value of a good error message. Take a look
Ruby: a simple example of Binary Search (Binary Search) algorithm.
In computer science, binary search (English: binary search), also known as binary search (English: half-interval search), and log search (English: logarithmic search ), it is a
How to install the Redis database in Linux and share with the automatic STARTUP script, linuxredis
Install Redis
(1) download Redis
wget http://redis.googlecode.com/files/redis-2.2.11.tar.gztar xzvf redis-2.2.11.tar.gz
(2) Compile and install
Analysis of Proc class and Proc class method Proc. new in Ruby, procproc. new
Proc is the process object obtained after the block and its context (the scope of local variables and the stack framework) are objectized. You can use Proc like an
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