ActiveRecord programming guide in Ruby on Rails, rubyonrails
Avoid modifying the default ActiveRecord (Table Name, primary key, and so on) unless you have a very good reason (such as a database not under your control ).Put the macro-style method before the class definition (has_many, validates, and so on ).
Preference has_expect: through is better than has_and_belongs_to_expect. Has_validation: through allo
This article mainly introduced the Ruby meta Programming Dream Lover Method_missing Method Detailed explanation, this article explained how I should use Method_missing, the method proxy, Define_method, when uses method_missing, the meta method and so on content , the need for friends can refer to the following
I recently read some articles (such as this one) to promote the use of method_missing in
Objective
As the RubyGnome2 library becomes more sophisticated and ruby1.9 performance improves, writing GUI programs with Ruby gradually turns from my hobby to an important part of my job.
Writing a program in Ruby is really fun, and it allows you to quickly get your ideas in a graceful way. A gem described in this article is an example of a very interesting feature with very little code that makes it eas
Rescue star for spelling mistakes in Ruby programming: did_you_mean gem
I often encounter spelling errors in Ruby development when class names or method names are misspelled. But I don't know it's just a spelling mistake. I will repeat it:
"It's so strange. It looks okay ..."
I often waste a lot of time on this kind of thing, but the reason m
, the File box command line, even the system variables, each time the new string from the pollution string operation, is also contaminated, can call tainted? () method to determine if it is contaminatedRuby security level, can be changed by modifying $safe global scalar, divided into 0-4, 5 levels0--is completely unconstrained, greater than 0,ruby will refuse to execute a contaminated string, greater than 2, will prohibit a large portion of file-relat
value with parentheses: Cat [Email protected]: ruby_src$./read.sh: 98765432DCBMust be curly braces Oh, otherwise read RET and Echo still in 2 process, equal to do not work Ah! You can do this:[Email protected]: ruby_src$my_val=$ (./read.sh)[Email protected]: Ruby_src$echo $my _val: 98765432DCBThis saves the returned results in the MY_VAL variable in the main bash process. Or you can handle it yourself in the while loop, because while loop and read are also in a process, the rewritten shell code
My memory has been poor and I need to take a look at it. Today I will look at Ruby's object-oriented programming content and write down some of these concepts for future reference.
Basic concepts:
I. Local variables, global variables, instance variables (object variables), and class variables.
II. Class Method and instance method (Object method ).
3. Inheritance.
4. Override method.
5. Reflection.
Sat. Encapsulation. (Public, private, protected
Ruby calculates the maximum sum of Adjacent Elements in the array.
Wei renyan 2010.8.21
I recently studied programming Pearl River and was very interested in the questions raised in the book. So according to the description in the book, I used Ruby to solve the related problems. The problems I learned today are as follows:
This is a problem in Chapter 8th of
Most of Ruby's built-in types are similar to other programming languages. Mainly have strings,integers,floats,arrays and so on. However, only the scripting language,
such as Ruby,perl, and awk provide support for built-in expression types. Shame: Regular expressions are a powerful text-processing tool, albeit covert.
They are very different than simply adding an interface class library.
A regular express
has all the instance methods of a. But let's think about what happened when we called @b.hi. Your ruby environment goes along the inheritance chain to find hi this way, in the end, just before throwing a nomethoderror, it tuned method_missing this method.
In the example above, the situation is not bad, after all, there are two trivial classes to look for. But usually, we are programming in the context of
When asked this question today, it was always considered a broader concept, even though I have used these characteristics, but have never known this is called "meta programming" until today when people ask, just epiphany some, and then on the Internet and their own flat practical some metaprogramming make a small sum.
The so-called metaprogramming in Ruby is the technique of manipulating language structure
Binding a distributed Logger with Ringydingy
Ringydingy allows us to DRY up our server code a bit. We no longer have the remember a whole lot of messy rinda API calls. Instead, we can wrap it up with a line or both of ringydingy code. Let's look at our "distributed Logger" application to see how we can make it more DRY.
Server
Client
Ring_server output
Server output
Client outpu
Adapter modeadapter patterns can be used to wrap different interfaces and to provide a unified interface, or to make an object look like an object of another type. In a static type of programming language, we often use it to satisfy the characteristics of a type system, but in a weakly typed programming language like Ruby, we don't need to do that. However, it st
178
Persisted AMQP Queues
Subscribing to a Message Queue
Topic Queues
Fanout Queues
Page 193 does not practice feeling completely do not look in ...
Conclusion
Endnotes
The book is over for the time being. Basic is the first chapter of serious practice, the back is grass grass over again. Technical books do read a few more times to be able to digest better, and later use or have time to read it again. Thank the author for his har
This article mainly introduces the method_missing of Ruby Meta programming, this article introduces a phenomenon that causes death cycle when using method_missing, the friend who need can refer to the following
We know the top-level domain, what is the self of the domain defined?
The code is as follows:
Puts self #main
Puts Self.class #Object
We know that when a method is invoked, if there is no object
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.