What's block?
In Ruby, block is not uncommon. The official definition of block is "a parcel of code". Of course, I don't think this explanation will make you more aware.
A simpler description of block is "a block is a piece of code stored in a
In this chapter we will discuss more Ruby process control.
Case
We use case statements to test for ordered conditions. As we have seen, this is quite close to the switch of C,java, but more powerful.
Ruby> i=8
ruby> case I
| When 1, 2..5
| Print "
tend to the literal notation of arrays and hashes (unless you need to pass arguments to their constructors).
# bad
arr = array.new
hash = hash.new
# good
arr = []
hash = {}
You always use%w to define an array of strings
IteratorDefined
A Ruby iterator is, simple A, can invoke a block of code.
Block is typically followed by method, and the code in the block does not necessarily execute
If there is a yield in method, the code in its block is executed
Ruby is an open source dynamic programming language that has beautiful syntax for building scalable Web applications. Ruby Gems can be a good way to improve the development efficiency of ruby developers.
There are several ways to install Ruby on an
When it comes to Ruby, it's just a reflex to think of rails, which seems to have only one use for Ruby, rails. Although I didn't write rails, I thought the Ruby language itself was far more attractive than the third-party framework of rails. It is a
1, http://rubyinstaller.org/downloads download Rubyinstaller and Developmentkit (note the version number to correspond)2, installation Rubyinstaller and decompression Developmentkit3. Open cmd, enter Developmentkit extract directory, execute ruby DK.
Steps 1Install homebrew, install the package required for the system through itRuby-e "$ (curl-fssl https://raw.github.com/mxcl/homebrew/go/install)"After the installation is complete, brew doctor self-TestSteps 2Installing Curl-l Https://get.rvm.io
For detailed documentation, you can click the official instructions on GitHub, which is only an English version.
Https://github.com/thoughtbot/shoulda-matchers
Shoulda-matchers provides test: Unit-And rspec-compatible one-liners that test common
Summary of basic operation methods for Hash types in Ruby, rubyhash
1. Create a hash:Just like creating an array, we can create a Hash instance using the Hash class:
H1 = Hash. new # default value: nilh2 = Hash. new ("This is my first hash instance")
The example parses the value types and constants in Ruby AND the ruby numerical constants.
Number)Integer)There are two types of integer types. If the value is within 31 characters (four bytes), it is a Fixnum instance. If the value is exceeded, it
Notes for variable reference IN Ruby: Ruby variable reference
In the expression, when Ruby sees a name like a, it needs to determine whether a is a local variable reference or a call to method a without parameters. Ruby uses a heuristic method to
Some brief translations of gem (You are welcome to raise questions for discussion ).
This article is mainly used in two aspects.
1. I hope to provide some help to rails colleagues. The translation level is limited. I will post Chinese and English
Common Ruby file operation code instances and ruby code instances
# Create a 222. rb file and the input character File = file. open ("222.rb"," w + ") file. puts "123 \ nwadwa \ n12124124 \ ndwdw" file. close # output 222. rb content File. open ("222
Ruby uses threads to implement typical producer and consumer problem code instances.
Sample Code:
Copy codeThe Code is as follows:Require "thread"Puts "ProAndCon"Queue = Queue. new # Use the Queue queue for Thread SynchronizationProducer = Thread.
11 questions about Hash in Ruby and rubyhash
Recently I am studying Rails because the java language I learned is the Getting Started language. a little uncomfortable. in particular, Ruby's Hash. however, you will be able to think about it in detail.
Jquery implements saving selected users, while jquery implements users
1 Introduction
Functional requirements:
1. Select the user interface and display it in a pop-up box.
2. Dynamic Loading of page options (department and user)
3. Save the selected
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