Ruby Tutorial: How to get started with the Ruby programming language

Source: Internet
Author: User

When learning a new programming language, we must be clear about a few questions:

What is the type model of the language?

Strongly typed / weakly typed, static type / dynamic type

The type model changes the way the problem is handled and controls how the language runs

What is the programming paradigm of language?

Object-oriented, functional, procedural, etc.

How to interact with the language?

Compiling, interpreting

What is the judgment structure of language (decision construct) and the core data structure?

What core features make this language unique?

Because each programming language has its own set of idiomatic methods, each with its own strengths and shortened, by learning different programming languages, you will understand which language is best suited to solve your immediate concerns. Here's an example of the Ruby programming language I'm learning, to tell you what I'm going to focus on and see my Ruby programming language (http://www.maiziedu.com/course/ruby/ ) several points of interest.

Introduction to Ruby programming language

Invented by as (Yukihiro Matsumoto) about 1993 years

scripting language, interpretive, object-oriented, dynamic type

Now that the Ruby version installed on my machine is 2.1, you can use the following command to query:

$ ruby-v

Ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-darwin14.0]

The specific installation does not do too much introduction, on the official website to consult the relevant information on different platforms, here is a simple example

IRB (main):001:0> properties = [' good ', ' bad ', ' clever ', ' stupid ']

= = ["Good", "bad", "clever", "stupid"]

IRB (main):002:0> Properties.each {|property| puts "I am #{property}."}

I am good.

I am bad.

I am Clever.

I am stupid.

= = ["Good", "bad", "clever", "stupid"]

Take a look at how Ruby iterates and values are replaced, and we'll look into it later. It is important to note that this language, which is easy to write, is generally less efficient. But the efficiency of development and the efficiency of execution are often the fish and bear paw, many times have to choose.

Let's look at a longer example:

IRB (main):001:0> puts ' Hello, wdx '

Hello, Wdx.

= Nil

IRB (main):002:0> friend = ' Snake '

= "Snake"

IRB (main):003:0> puts "Hello, #{friend}"

Hello, Snake.

= Nil

IRB (main):004:0> friend = ' Queit '

= "Queit"

IRB (main):005:0> puts "Hello, #{friend}"

Hello, Queit.

= Nil

Here we can see the following points:

Do not declare variables

Each Ruby code will return a value

Single quotation marks for direct interpretation

Double quotation marks contain strings that are replaced by strings

Programming model

Ruby is a purely object-oriented language. As you can see from the following example:

IRB (main):001:0> 233

= 233

IRB (main):002:0> 233.class

= Fixnum

IRB (main):003:0> 233 + 233

= 466

IRB (main):004:0> 233.methods

=> [:to_s, :inspect, :[email protected], :+, :-, :*, :/, :d IV,  :%, :modulo, :d ivmod, :fdiv, :* *, :abs, :magnitude, :==, :===,  :<=>, :>, :>=, :<, :<=, :~, :&, :|, :^,  :[], :<<, :>>, :to_f, :size, :bit_length, :zero?, :odd?,  :even?, :succ, :integer?, :upto, :d ownto, :times, :next, :p red,  : CHR,&NBSP;:ORD,&NBSP;:TO_I,&NBSP;:TO_INT,&NBSP;:FLOOR,&NBSP;:CEIL,&NBSP;:TRUNCATE,&NBSP;:ROUND,&NBSP;:GCD,  :lcm, :gcdlcm, :numerator, :d Enominator, :to_r, :rationalize, :singleton_ Method_added, :coerce, :i, :[email protected], :eql?, :remainder, :real?,  :nonzero?, :step, :quo, :to_c, :real, :imaginary, :imag, :abs2,  : Arg, :angle, :p hase, :rectangular, :rect, :p olar, :conjugate, :conj, :between?, :nil?  :=~, :!~, :hash, :class, :singleton_class, :clone, :d Up, :taint,  :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?,  :methods, :singleton_methods, :p rotected_methods, :p rivate_methods, :p ublic_methods,  :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_ defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, : send, :p ublic_send, :respond_to?, :extend, :d isplay, :method, :p Ublic_method,  :singleton_method, :d efine_singleton_method, :object_id, :to_enum, :enum_for, : EQUAL?,&NBSP;:!,&NBSP;:!=,&NBSP;:INSTANCE_EVAL,&NBSP;:INSTANCE_EXEC,&NBSP;:__SEND__,&NBSP;:__ID__]

See, everything inRuby is an object, for example, a number is an object of type fixnum , and we can use it . to invoke various methods of the object.

Judge

We can also use examples to study the study.

Have you read the above introduction to the Ruby programming language have a certain understanding? From these points of view, the focus is to understand the Ruby programming language and other languages, but also know the characteristics of the Ruby language. To learn more about the Ruby programming language, you can search the wheat Academy for more Ruby Video Tutorials.


Ruby Tutorial: How to get started with the Ruby programming language

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.