Use C ++ to compile Ruby program extension tutorials.
One of Ruby's coolest features is to extend it using the application programming interface (API) defined in C/C ++. Ruby provides the C header file ruby. h, which is accompanied by many features that can be used to create Ruby classes, modules, and more. In addition to header files, Ruby also provides several other high-level abstractions to expand ruby built based on local Ruby. h. This article will introduce Ruby Interface for C ++ Extensio
to the function as a closure. The closure is to wrap the functions and variables to extend the life cycle of the variables.
Array 2.3
animals = ['lions', 'tigers', 'bears']puts animals[1]puts animals[-1]puts animals[0..1]
The above code has a syntactic sugar.-1 indicates that the last-to-last element is returned. Of course, 1 indicates the second element, just like other languages.
Animals [0 .. 1] uses the interval learned yesterday to indicate the elements from 0 to 1.
Ruby gives us six ways to complete a task when we encounter the need to invoke the operating system shell command:
1.Exec Method:
The Kernel#exec method replaces the current process example by invoking the specified command:
Copy Code code as follows:
$ IRB
>> exec ' echo ' Hello $HOSTNAME '
Hello nate.local
$
It is noteworthy that the Exec method replaces the IRB process w
way to use the filter is to first put the deepest IRD, and then place the camera on the nightshot and Automatic Exposure files.
Then you can see your exposure time, if it is between 1/30-1/60. Then you can take a video. If the time is lower than 1/30, it indicates that this filter is relatively deeper than the current situation. Please change it to an IRC. Similarly, you can change it to an IRB. If not, it indicates that the current environment is ve
:
IRB (main): 045: 0> bankaccount. getinterestrate=> 6.5
In fact, the "new" method used to create a class instance is a class method. Therefore, when you enter "rectangle. New" in the program, you actually call the new class method-this is provided by ruby by default.
Inheritance
One of the principles of object-oriented programming is to support class hierarchies. Just like the categories of things in nature, classes allow inheritanc
call a method,
* No:
If the last expression on the left contains *, the redundant elements on the right are substituted into the expression with * as an array. If there are no redundant elements on the right, the empty array is substituted into it.
* Foo = 1, 2, 3 # Foo = [1, 2, 3] Foo, * bar = 1, 2, 3 # Foo = 1; bar = [2, 3]
* Variables used in method definition to indicate variable lengths:
[From "programmingruby "]
Variable-length argument lists
But what if you want to pas
Go to Script/consle after upgrading Ruby and Rails:
Copy Code code as follows:
/usr/local/lib/ruby/1.8/irb/completion.rb:10:in ' require ': No such file to load-ReadLine (Loaderror)
From/usr/local/lib/ruby/1.8/irb/completion.rb:10
From/usr/local/lib/ruby/1.8/irb/init.rb:252:in ' require '
From/usr/local/lib/ruby/1.8/
whether the command execution result is successful or failed.
Copy codeThe Code is as follows:$ Irb> System 'echo "hello $ HOSTNAME "'Hello androidyue=> True> Puts $?Pid 11845 exit 0=> Nil> System 'false'=> False> Puts $?Pid 11858 exit 1=> Nil>
System will assign the exit status code of the process to $ ?, If the program Exits normally, $? The value is 0, otherwise it is not 0. By checking the exit status code, we can throw an exception in the ruby s
=~/Black/}=> trueYou can also change a method:
>> Provinces.keys.all? {|province, abbr| province =~/Mountain/}=> falseHash
Each iteration of a hash, the hash will be yield into your code block, each time a key/value pair. Each pair is an array of two elements.
Range
>> r = range.new (1, 10)=> 1..10>> R.one? {|n| n = = 5}=> true>> R.none? {|n| n% 2 = 0}=> false>> r = Range.new (1.0, 10.0)=> 1.0..10.0>> R.one {|n| n = 5}Nomethoderror:undefined method ' One ' for 1.0..10.0:rangeDid you mean? O
Network security is a comprehensive, complex project, any network security measures can not guarantee foolproof. It is therefore essential that, in the case of some important sectors, the network is attacked, how to track cyber attacks, and to track down and bring to justice the attackers.Tracking cyber attacks is the source of the events that occur. It has two aspects meaning: One refers to the discovery o
%{
Include header file
#include "test.h"
%}
Interface add
int add (int,int);
2, the preparation of wrap documents
Copy Code code as follows:
Swig-c++-ruby test.i
Get Test Package file Test_wrap.cxx
3, the preparation of test.h and Test.cxx
Copy Code code as follows:
Test.h
#ifndef _test_test_h
#define _test_test_h
extern int Add (int,int);
#endif
Test.cxx
#include "test.h"
int add (int left,int right)
{
return left+ri
or failure.
Copy Code code as follows:
$ IRB
> System ' echo ' Hello $HOSTNAME '
Hello Androidyue
=> true
> puts $?
PID 11845 Exit 0
=> Nil
> System ' false '
=> false
> puts $?
PID 11858 exit 1
=> Nil
>>
System assigns the status code of the process's exit to $, and if the program exits normally, the value of $ is 0, otherwise it is not 0. By detecting the exit status code we can throw an exception i
Scott/tiger @ // 192.168.0.91/orcl
SQL * Plus: Release 11.2.0.2.0 production on Fri Sep 23 04:39:08 2011
Copyright (c) 1982,201 0, Oracle. All rights reserved.
Connected:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0-Production
With the partitioning, OLAP and Data Mining options
SQL>
Download oci8 installation link: http://ruby-oci8.rubyforge.org/en/, decompress the file, and run make and make install. Before run
Suddenly I found out that Ruby was good too, I was kind of thinking about learning
Introduced
This is a short introduction to Ruby and it takes only 20 minutes to complete the reading. This assumes that the reader has already installed Ruby, and if you are not installing it, please visit the official Ruby website for download and installation before reading.
Interactive Ruby
Open irb (interactive ruby Shell):
If you are using Mac OS X, open the Ter
Illinois State Rolin Medos--(American business information)--InternationalInformationThe Audit Association (ISACA) today announced the launch of a newInternetSecurity certification portfolio, combining skills training with hands-on exams and certifications for the first time. These seven new cybersecurity Nexus (CSX) certifications help professionals plan and develop their careers in changing areas while helping employers make up for skills gaps. Global knowledge, the leading provider of it and
Machine learning is accelerating the pace of progress, it is time to explore this issue. Ai can really protect our systems in the future against cyber attacks.
Today, an increasing number of cyber attackers are launching cyber attacks through automated technology, while the attacking enterprise or organization is still using manpower to summarize internal securi
Opening
Empty is the color, and the color is empty.Empty and empty, in the Ruby language, everything is an object.
Ruby is an object-oriented language (object oriented Language), and the object-oriented concept is much more robust than other languages.
The raw type data and object type data in Java are not present in Ruby. Most of the stuff in Ruby is an object.
So, to master the metaprogramming of Ruby and Ruby, the object is the first compulsory lesson. This is the time to focus on the obj
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.