It is early to know that Ruby has 4 methods of equality, namely: "= =", "= =", "Equal?" and "Eql?", the usual procedures are used, but feel a lack of in-depth understanding of it, reading the rails part of the source code when you can not grasp the
=begin conditional judgment statements include if statements, unless statements, case statements,=end#if statements =beginif conditions then processing 1elsif conditions 2 then processing 2else processing 3end=enda = 10b = 20if a >
After reading Ruby for a few days, I found many well-known syntax features in C #. Ruby was available a few years ago:
1. The Params keyword in C #
Class program {static void main (string [] ARGs) {console. writeline (sum (); console. writeline (
Ruby's array is basically used. Compared with arrays in C #, the least habit is to allow negative indexes (somewhat similar to Javascript)
Arr = [3, 4, 5, 6, 7, 8, 9] puts arr [0] #3 puts arr. first #3 puts arr [arr. length-1] #9 puts arr [arr.
An important feature of closures is that variables defined inside a process (method) can be referenced even after the method call is complete! (That is, the lifecycle is extended)
Def method (n) puts "n = # {n}"; # Return proc {| I | n + = I} # key:
When testing the model, one change was observe. I wanted to test it, but the observer refused to execute it in rspec, but there was no problem with test env in the console.
It took me a day to debug and finally failed to solve the problem. If you
My environment is Ruby 1.9.2p290 + rails2.3.4 + mysql5.5.15. When I run "DB: migrate", the error message is as follows:!!! The bundled mysql. RB driver has been removed from rails 2.2. Please install the MySQL gem and try again: Gem install
# Close command display @ echo off # message ECHO now, listing the controller, please not shutdown the DOS file! # Switch to the current path. Put the. BAT file and the. RB file together. set Pa = % Cd % # execute the ruby script Ruby test. rbpause
How many methods do you have to create a method? Most people may think of the def keyword Ruby.
Code
# Common method
DefTele_you
Puts"I am anleb"
End
# General method def tele_you puts "I am anleb" End Ruby code
#
Class A def self. ask1 puts "the method of Class" End def ask2 puts "the method of instance" endend
# Method of the Instance Object of the class. The method belongs to the new instance object generated by the class.P a. Methods. LengthP a. Class.
ArticleDirectory
Ruby-adding a directory to $ load_path-what does it do?
Similarities: all three are defined in the kernel and contain the meaning of something.
Differences:
1. requre and load are used for files ending with. RB.
In Ruby, the so-called block-based method refers to the abstraction of the control structure. It was initially designed to abstract loops, so it is also called an iterator.Syntax: method_name do... end or method_name {}
1
#
Block call
"Require" can be merged into. RB proposal, and can be omitted ". RB ". in addition, it will only commit at the first time. If it is "require" again, it will ignore
Code highlighting produced by Actipro CodeHighlighter
Rails3 is coming out, and it's time to start learning. You can find a good tutorial on the Internet: http://railscasts.com/episodes, which can be downloaded.
Unfortunately, only 10 entries are displayed on each page and cannot be downloaded in
Get the currently running method name in Ruby on bigbold
Code Fragment:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Module KernelPrivate
Def
This_method_nameCaller [0]
= ~
/
'
Mailfactory is a simple mail package on rubyforge. With this package, we can easily send emails with attachments and HTML formats. However, currently, mailfactory has some problems in Chinese support, A patch is required.
Install mailfactory
ATTR _ * in ruby _*
In Java, get and set are used to assign values to and read variables.
In ruby:
Read:
Def name @ nameend
Assignment:
Def name = (myname) @ name = mynameend
You can use attr_reader and attr_writer, or attr_accessor.
For
The new version of will_paginate has abandoned this practice and switched to the gem method. This article builds an application named foobar to understand the usage of will_paginate.====================================C: \> rails foobar-d mysqlC: \>
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