I've been learning about rails, because learning Java is an introductory language. It's a bit of a bad fit. In particular, Ruby's hash. But it's just a matter of thinking it through. It's basically a key-value. There is no big problem with writing in the beginning. This is a log I saw on the Internet.
1. How do I create a hash?
Copy Code code as follows:
x = hash.new
x = {}
x = {: A => 1,: B => 2}
These are the ways to create a hash.The first is the same as the sec
● Exception Handling
● Thread
Note: All the code in this article is tested based on Ruby version 1.8.7.
Class hierarchy in Ruby
The class hierarchy in Ruby is tricky. Create a Cat class and explore its hierarchy (see Listing 1 ).
Listing 1. Implicit class hierarchy in Ruby
irb(main):092:0> class Catirb(main):093:1> end=> nil irb(main):087:0> c = Cat.new=> #
All objects (or even user-defined objects) in
example, and the subsequent example only outputs the value of the variable directly.
$ _
The last string read by gets or Readline. If EOF is encountered, it is nil. The scope of this variable is a local domain.
Ruby code
IRB (main): 006: 0 >$ _
=> Nil
IRB (main): 007: 0> gets
Foobar
=> "Foobar \ n"
IRB (main): 008: 0 >$ _
=> "Foobar \ n"
$
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 can kill ourselves from the current process.Copy codeThe Code is as follows:> 'Kill-9 # {$ $ }'[1] 17170 killed irb$? Indicates the status of the latest sub-process.Copy codeThe Code is as follows:> 'Echo
In RubyProgramYou will often see some variables starting with $. These are not the global variables we set in the program, but the variables that have been set inside the system, they represent some specific meanings. Some common internal variables are collected below, and some simpleCodeWhat they mean: Local Domain:
It can only be valid within a thread scope. The following can also be seen as a local variable in the thread.
PS: the variables described here are related to regular expression m
, the newly added three network segments of the gateway configuration on the A-block core, if not configured Mc-lag, four cores formed a loop, through the configuration Mc-lag, to implement the anti-ring mechanism. on The aggregation layer, two core switches are connected to each other, and there is also a loop, where you can use Juniper's own anti-ring configuration RTG instead of spanning tree protocol. RTG is easier to use than Mc-lag, but can only be used when one end is a single device, so
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. basically, all are passed Key-Value. there is no big problem except that it is not suitable for writing at the beginning. this is a log I saw on the Internet.
1. How to Create a Hash?
Copy codeThe Code is as follows:X = Hash. newX = {}X = {: a => 1,:
. Working with Ruby strings: defining strings
message = ' Heal of the world ... '
puts message
message1 = "Take home Rs #{100*3/2}"
puts Message1
Output:
#/string1.rb
# Heal the world ...
# Take Home Rs 150
Here, the first string is defined with a pair of single quotes, and the second string is defined with a pair of double quotes. In the second string, the expression in #{} is evaluated before it is displayed.
Another useful string definition method is commo
Transferred from: http://www.jb51.net/article/48802.htmRuby is filled with a series of hidden variables, and we can get some interesting information from these pre-defined global variables. Global process variables$$ represents the currently running Ruby process.>> $$= 17170We can kill it ourselves from the current process.>> ' kill-9 #{$$} '[1] 17170 killed IRB$? Represents the state of a recent child process>> ' echo Hello '= "Hello\n">> $?= = #>> $
When getting started with Ruby, it is easy to get confused by the small trick of its classes and modules. Here we will write it out to help you understand it.
1. Everything in ruby is an object
Ruby is a Ground Object. All the components you see are objects. Numbers are objects, strings are objects, classes are objects, modules are objects, and even classes are objects ......
irb(main):001:0> 1.is_a? Object=> trueirb(main):002:0> Object.is_a? Object=
Ruby is filled with a series of hidden variables, and we can get some interesting information from these predefined global variables.
Global process variables
$$ represents the currently running Ruby process.
Copy Code code as follows:
>> $$
=> 17170
We can kill ourselves from the current process.
Copy Code code as follows:
>> ' kill-9 #{$$} '
[1] 17170 killed IRB
$? Represents the state of the most recent chi
What is Symbol?
Ruby is a powerful object-oriented scripting language (the ruby version used in this article is 1.8.6). In Ruby, symbol represents a "name", such as a string name and an identifier name. To create a symbol object, add a colon Before the name or string:
Create a symbol object
:foo:test
:”abc”:"I am a boy”
You may ask, why is there a character string name? This is because in ruby, a string is also an object, that is, a string object. No matter its s
(venue, date) \ n">> f.gets=> "@venue = venue\n"ReadLine and gets the same line can read the file, different places is to the end of the file, gets return Nil,readline will error.
Try this again:
>> F.read=> "@date = date\n end\n\n def price= (price) \ n @price = price\n end\n\n def venue\n @venue \ n end\n\n def date\n @date \ n end\n\n def price\n @price \ end\nend\n ">> f.gets=> Nil>> F.readlineEoferror:end of File reachedFrom (IRB): 14:in ' Rea
method! No, it's just a convention.
To_*
11:54 * * *
Ruby has some methods that start with to_, and they can transform objects. such as to_s (converted to strings), To_sym (converted to symbols), to_a (convert array), to_i (Convert integer), to_f (convert floating-point decimal).
to_s: Converting strings
Do an experiment:
>> "Hello". to_s=> "Hello"Try again:
>> ["One", "two", "three", 4, 5, 6].to_s=> "[one\", \ "two\", \ "Three\", 4, 5, 6] "Try again:
>> Object.new.to_s=> "#And do an ex
.
Listing 1 is an example.Listing 1. Processing Ruby strings: defining strings
message = 'Heal the World…'puts messagemessage1 = "Take home Rs #{100*3/2} "puts message1Output :# ./string1.rb# Heal the World…# Take home Rs 150
Here, the first string is defined by a pair of single quotes, and the second string is defined by a pair of double quotes. In the second string, the expression in # {} is calculated before display.
Another useful string definition method is usually used for multi-line strin
For Ruby introduction, see: http://www.ruby-lang.org/zh_CN/about/
I. IRB
Interactive Ruby help and consoleProgramIn Windows.
You can directly execute Ruby in IRB.Code. For example:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
IRB (main ):
001
: 0
>
"
Hello World
"
=>
"
Hello World
"
Ii. Puts commands and nil
Code hi
Calabash-android command line usage
This article describes how to use the calabash-android command line. Through examples, you can familiarize yourself with the ruby APIs and common Console Commands called by calabash-android, such as query, touch, and wait .,. Familiarity with these Apis helps us write custom feature.
Step 1: Download the app
The app used in this article is the hacker headlines. Click here to download it. Shows the view elements in the app:
Step 2: Open the command line and en
One of the coolest features of Ruby is to extend it using the Application programming interface (API) defined by C + + +. Ruby provides the C header file Ruby.h, which comes with a number of features that you can use to create Ruby classes, modules, and more. In addition to the header file, Ruby offers several other high-level abstractions to extend Ruby based on the local ruby.h build, this article is about Ruby Interface for C + + Extensions or Rice.Create a Ruby extension
Before doing any Ru
We know that,QtpProvides object spy tools, Object Library recording functions, or descriptive programming to quickly identify objects,To some extent, scripts can be generated in batches. Correspondingly, I am thinking about such a good tool andTechnologyWhy is watir not supported?Maybe in the futureAutomationStudents and the watir development team can work hard to meet this requirement.
Another question is thrown out. Do we have to find and select the objects we want to operate in so long code t
We often interact with the operating system or execute Shell commands in Ruby. Ruby provides us with many ways to accomplish this task.
ExecKernel#execReplaces the current process by executing a given command, for example:$ irb>> exec ‘echo "hello $HOSTNAME"‘hello codefun$Note exec echo Replace the process with the command irb , and then exit. Because Ruby actually ends the method, it can only be used i
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.