A running program often encounters unexpected problems. A file to read does not exist; When you want to save some data, the disk is full; The user may enter inappropriate data.
ruby> file = open ("Some_file")
ERR: (eval): 1:in ' open ': No such
1. Create a hash: just like creating an array, we can create a hash instance from the hash class:
H1 = hash.new #默认值为nil
h2 = Hash.new ("This is the My-my-a-hash instance") #默认值为 "This is me-a-my-a-hash instance":
The above
I have recently considered a lot of metaprogramming (metaprogramming) issues and would like to see more examples and explanations of this technology. For better or worse, Metaprogramming has entered the Ruby community and is a standard way to
Get the current date and time:
The following is a simple example to get the current date and time:
#!/usr/bin/ruby-w
time1 = time.new
puts "current time:" + time1.inspect
# Time.now is a synonym:
time2 = Time.now
puts "current time:" +
Ruby supports a modern language of a rich array of operators. Most operators are actually method calls. For example, A + B is interpreted as a,+ (b) The method of the object referenced by the variable is called a parameter with B as its.
For each
BlockDefined
Some_array.each {|value| puts value + 3}
sum = 0
other_array.each do |value|
Sum + = value
puts value/sum end
A block are somewhat like the "Body of" anonymous method
Block can take parameters
Block only
Ruby-v #查看ruby version ruby-e ' require ' watir; Puts Watir::ie::version ' #查看watir版本
RVM list Known #列出已知的ruby版本
RVM Install 1.9.3
RVM Use 1.9.3 | RVM Use System
RVM Use 1.9.3--default
RVM List #列出本地ruby版本
RVM Remove 1.9.2
See RVM Practical
Today we're learning about arrays and hashes, and arrays are often used in many programming languages.
Array:
An array is a container for storing data, and in Ruby, the data stored in an array can be any type of data; This differs from Java, in
Each program that is running on the system is a process. Each process contains one or more threads.
A thread is a single sequential control process in a program that runs multiple threads at the same time in a single program to accomplish different
Imagine how an active record handles SQL, so let's take a look at the Find method's: Conditions parameter, which is like this when called: Find (: all,:conditions=> ...), here: The conditions parameter determines which records the Find method
Honestly not really like to discuss Ruby and Python contrast, it seems to always put two languages in the opposite position, I think it is not necessary, the same dynamic language, also is the interpretation of scripting language, many features are
Transferred from: http://www.jianshu.com/p/728184da1699Gem Introduction:Gem is a standard package for managing Ruby libraries and programs, and it is easy to find, install, upgrade, and uninstall packages through Ruby Gems such as
This chapter targets: Detail view, rails routing, Asset Pipeline, Sass1. Bootstrap is an open source web design framework developed by TwitterMockup is a Web concept diagram, often referred to as a "wireframe" in the web, used to show sketches of
return, break the next use of these keywords involves jumping out of the scope of the problem, and their difference is that different keywords jump out of the scope of the purpose of the different, because there is a block of code will cause some
I installed a watir myself. When I tried the sample, the uninitialized constant windows: API: Error always appeared. This error is returned.
Google, find someone and say it's okay to update Win32 utils gem.
The specific cause is unknown.
Ruby is filled with a series of hidden variables. We can get some interesting information from these predefined global variables.
Global process variable
$ Indicates the currently running ruby process.Copy codeThe Code is as follows: >>$ $=> 17170We
Python class inheritanceI. Overview
One of the main functions of Object-Oriented Programming (OOP) is "inheritance ". Inheritance refers to the ability to use all the functions of an existing class and extend these functions without re-writing the
Example of writing code for exception handling in Ruby, and ruby Exception Handling
A single exception uses the fail keyword only when an exception is caught and thrown repeatedly (because you do not fail here, but are accurate and intentionally
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.