method continues.
Lambda-flavored proc, use the normal number of arguments when called:
>> Lam = lambda {|x| p x}=> #>> Lam.call (1)1=> 1>> Lam.callArgumenterror:wrong Number of arguments (given 0, expected 1)From (IRB): 105:in ' blocks in irb_binding 'From (IRB): 107From/usr/local/bin/irb:11:in ' >> Lam.call (1,2,3)Argumenterror:wrong Number of arguments (giv
I suddenly found that ruby is also good, and I want to learn it.IntroductionThis is a short Ruby entry, and it takes only 20 minutes to complete. Here we assume that you have installed Ruby. If you have not installed Ruby, visit the official Ruby website to download and install it.Interactive RubyOpen IRB (Interactive Ruby shell ):If you use Mac OS X, open the terminal window and enter irb;If you are using
I suddenly found that Ruby is also good, and I want to learn it.
Introduction
This is a short Ruby entry, and it takes only 20 minutes to complete. Here we assume that you have installed Ruby. If you have not installed Ruby, visit the official Ruby website to download and install it.
Interactive RubyOpen IRB (Interactive Ruby shell ):
If you use Mac OS X, open the terminal window and enter IRB;
If y
created above (the index is 2). Note that you can use the bracket flag or the At method to retrieve the object reference in the array.
IRB (main): 003:0> shirt_information[2]
=>
IRB (main): 004:0> shirt_information.at (2)
=> 32
Interestingly, you can also use a negative index to refer to an element in an array. A negative index is counted from the tail of the array.
When pry is used, you will feel that the previously used debugger method is so complicated and troublesome that it brings up the troubles of rails S and takes time to enhance IRB's functions,
By default, the pry configuration is enough, so that the rails console can also rest.
Installation:
Add in gemfile
gem ‘pry‘, :group =gt; :development
Then execute
bundle install
You can.Usage:
Replace the IRB method with pry and run the following command directl
, SetvaluePlaced in an array1.
condition ifTrue: [doSomething] ifFalse: [doSomethingElse].Is a keyword message. The code in parentheses is calledClosureOrCode block. This sample code will:ifTrue :ifFalseMessage sentconditionObject. If the condition is true, Smalltalk executes[doSomething]Code block; otherwise, execute[doSomethingElse]Code block.
Ruby supports message transmission and direct method calls. Message transmission in ruby looks a little different, but the premise is consistent. In L
Well, our function test code often has a small requirement: When a function in the test code throws an exception, the system automatically displays a debugging window. The debugging window should contain context information for the tester to debug the exception. "By the way, I thought something new. It turned out to be a bit boring breakpoint for Ruby on Rails! ", The readers began to comment with disdain. Well, the old man's words won't go wrong. It is indeed a common breakpoint in ror. But bef
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 Terminal window to enter IRB;
If you us
Let's take a look at some tips for debugging this time.
First, and most importantly, writing test code, writing unit tests and functional tests in rails is simple, using them to reduce the rate of bugs, or to avoid bugs in your previous code.
The test code tells you what works and what doesn't, and the test code helps you isolate the problematic code, because sometimes the bug doesn't show up quickly.
If the problem occurs in a model, we can use the script Script/console to simulate an
jruby-1.7.3 and generates a '. Rbenv-version ' file
Resolve MacOSX the method of compiling Ruby without entering Chinese in IRB
Install the homebrew readline, then enter the source directory, recompile the installation Readline.bundle
Brew Install ReadLine
Brew link readline
cd src/ruby-1.9.3-p392/ext/readline
Ruby Extconf.rb- with-readline-dir=$ (Brew--prefix readline) make
Install
The solution under the rbenv
Brew Ins
Network War law: You must know this. Network War law:
Recently, the New York Times reported that the United States may use nuclear weapons to counter the destructive cyber attacks of hostile countries. In November 2017, a video entitled "Slaughterbots" was widely spread on social media and alleged that "artificial intelligence (AI) the controlled drone fleet can launch precise attacks against thousands of unprotected victims." These two articles have
Gsub ()The first parameter is Reg, and the second parameter is the character that is replaced.Returns the changed string with no side effects on the original string.No match will return the original string.irb(main):001:0"regWord"=>"regWord"irb(main):002:0> str.gsub(/W/,‘w‘)=>"regword"irb(main):003:0> str=>"regWord"gsub! ()The original string is modified when there is a match.Nil is returned when there is n
col_names = something. column_names. finish puts DBI: Utils: XMLFormatter. table (rows) dbh. do ("delete from simple") rescue DBI: DatabaseError => e puts "error code: # {e. err} "puts" Error message: # {e. errstr} "ensure dbh. disconnect if dbhend
Problem:
But every time I perform the first step, config: unknown option -- with = dbi, dbd_mysql Try 'Ruby setup. rb -- help' for detailed usage will appear.
Cause analysis:
This is caused by dbi version problems.
ThereforeInstall the new versionThe
setup of RJB.
Download RJB
RJB can be downloaded in the form of a standard Ruby Gem package or its own compiled source code archive. For the demo, I recommend downloading the source code archive, so I'll use this approach. With less gossip, download the RJB 1.1.3 source. zip file (the latest RJB version is available at the time of this tutorial).
Be sure to set or update the following environment variables, which are required to install RJB:
Java_home must point to the Java SDK installation
_home/bin
Compiling and installing RJB
The next step is to compile and install RJB by executing the following command:
[root@san]# unzip Rjb-1.1.3.zip
[root@san]# cd rjb-1.1.3
[root@san]# Ruby setup.rb config
[root@san]# Ruby SETUP.RB setup
[root@san]# Ruby setup.rb Install
Confirm Installation Success
To confirm the success of the RJB installation, first invoke the Ruby Interactive console IRB:
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.