Just see the Ruby language developer as (Matz, full name is Yukihiro Matsumoto) and launched a new language development, called Streem, still in a very primitive phase, only three files, code on GitHub. Look at Matz's own description, Streem is a
When values are all shaped, sort by the values of the hash:h = {'a' = =1,'b ' ==2,'C ' +5,'d' = 4} H.sort {|a,b| a[1]b[1]} Output: [["a", 1], ["b", 2], ["D", 4], ["C", 5]] When we need to sort the hash, we cannot use the Sort method as
The count-taking method in Ruby is the most humane and flexible in the language I touch, which can be illustrated here for example:First, print 7 times "Hello,world", as follows:7.times{puts "Hello,world"} #在这里, puts function is equivalent to print+
Demand:Shopping Center cash register software, according to the customer to purchase the item unit price and quantity, calculates the expense, will have the promotion activity, hits 80 percent, 300 minus 100 and so on.One, use Factory
ARGFAn Io object that connects all the files specified in the argv into a file. If argv is empty, then it represents standard input. Synonyms $ArgvAn array that contains all the parameters specified by the command line. Synonyms $*DATARepresents all
Usually we use the following form when we write code, construct nested data, or initialize a variable:A | | = [] ; A = B | | C A = a | | []This form ensures that the variables are initialized when they are accessed, giving us a great deal of
Ruby-vVerify that Ruby is installed successfully and view the version numberRuby-e "puts ' hello '"Verify that Ruby is successfully installed and executableGem--versionLook at the version of RubyGems, for example, I have an output of 1.5.2 at this
#numbers are classified as certificate integer, floating-point number float (corresponding to double in other languages), and plural complex#integers are divided into fixnum and Bignum,fixnum and Bignum to each other, and these are the operations
There are a number of classic drive architectures in Ruby, such as enumerators and generators. This is a simple introduction to the concept of generators. The generator is a function requirement that produces an object at a time, or a method that
First, you need to add a delete link on the index page and provide a delete confirmation that the user confirms the deletion and deletes the data directly.Modify viewsModify the App/views/posts/index.html.erb as follows:our blogs
The previous index page, which shows Hello World, is now modified to show the data we entered in the Rails console.1. Modify the actionAs described in the previous section, "Ruby on Rails" and the route map I learned, modify the
How can we be reduced to writing compression and decompression tools with Ruby under UNIX? Go straight to the shell! But please allow this cat to be ashamed to play with Ruby this time! In fact, Ruby Gem has a lot of compression decompression
In Ruby we want to implement the method of traversing the specified directory, the method of the Internet is also very much, we can refer to reference, as shown in the following traverse.rb file content:#!/usr/bin/ruby def traverse (filepath) if
#R Read,#W Write,#a Append,#r+ Read or write from the head position of the file.#w+ Read-write mode, if the file already exists to empty the file, does not exist to create a new file,#A + If the file exists on the last side attached, create a new
First, take a look at the simple factory modelAdvantages of the Simple factory model: The factory class contains the necessary logical judgments, dynamically instantiating the relevant classes based on the client's choice, and, for the client, the
Chapter I.strings, numbers, classes, and objectsTo prove that Ruby is really good, Hello world can also be written in such a concise way:' Hello World '1. Input/outputPrint ('Enter your name') name=gets () puts ("Hello #{name} ")Note: Ruby is a big
Yum install RubyGem install rails-VWithout-V, the progress is not displayed, just like a dead machine, but not actually a dead machine.Yum install ruby-develNo plug-ins will be installed.Yum install SQLite-develHe will be stuck in SQLite
How to build a ruby gem
1. First you will creata a user in rubygem.org (https://rubygems.org /)
2. Create the directory structure like this:
Java code
$ Tree
.
── Cc_hola.gemspec
── Lib
── Cc_hola.rb
You can use any name but you must
The array size in Ruby can be changed at any time. The elements in the array only save references to objects.I. Definition
A = array. New ()
A = array. New (5) Create an array of five nil Elements
A = array. New () Create five arrays whose
Method for creating a method alias with the same name as the "keyword" in Ruby
Begin and end are ruby keywords, but Range is also known as begin and end instance methods. Now the question is: how to create their aliases?
If you use class Range;
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.