Tag:ruby

  • Print does not wrap, puts will wrap page 1 / 2

    Time:2020-6-17

    1. Print does not automatically wrap lines, and puts will automatically wrap lines. If a line is not enough, you can add “\” to connect Ruby code puts 6/2 Operation result: Ruby code Three 2. = =, EQL? Equal? Difference ==Equal value equal value equal value equal type equal value equal memory address equal A=1 […]

  • What is ruby and Ruby overview

    Time:2020-6-10

    Ruby is a powerful object-oriented scripting language, which can make you easily and quickly carry out object-oriented programming. Sometimes it’s a bit of a fuss to develop some small projects with formal object-oriented languages such as Smalltalk, Eiffel or C + +, and Ruby just can meet these requirements of object-oriented programming, You can also […]

  • Ruby Document Center – learning begins

    Time:2020-6-9

    First, you need to check whether ruby is installed. At the shell prompt (in this case, it means “%”, so don’t type%), type % ruby -v   (- V tells the interpreter to print out the Ruby Version), and then click enter. If ruby is installed, you will see the following information: % ruby -v ruby 1.6.6 (2001-12-26) [i586-linux]   If ruby is not […]

  • Simple Ruby example

    Time:2020-6-8

    Let’s write a function to calculate factorial. The mathematical definition of factorial is as follows: N! = 1 (when n = = 0)=N * (n-1)! (other cases) In ruby, you can write as follows: Copy codeThe code is as follows: def fact(n)          if n == 0            1          else            n * fact(n-1)            end        end   You may find the recurrence of end. Because […]

  • Ruby string processing

    Time:2020-6-7

    Ruby treats strings like numbers. We enclose them in single quotation marks (‘…’) or double quotation marks (‘…’) ruby> “abc”    “abc” ruby> ‘abc’    “abc” Single quotation marks and double quotation marks have different functions in some cases. A string enclosed by double quotation marks allows characters to be led out by a leading slash, and can be […]

  • Ruby regular expression tutorial

    Time:2020-6-6

    Let’s take a look at a more interesting program. This time, let’s test whether a string matches a description generated by a concise pattern encoding In these patterns, some characters or character combinations have unique meanings, including: Copy codeThe code is as follows: [] range descriptor (for example, [a – Z] represents a letter in […]

  • Ruby array tutorial

    Time:2020-6-5

    You can create an array by listing the elements in square brackets and separating them with commas. Ruby arrays can adapt to different object types ruby> ary = [1, 2, “3”]    [1, 2, “3”]   Just like the string mentioned earlier, arrays can be multiplied or added ruby> ary + [“foo”, “bar”]    [1, 2, “3”, “foo”, “bar”] ruby> ary * 2    [1, 2, “3”, 1, 2, “3”]   We can use the index to access any part of the array […]

  • Some simple examples of ruby

    Time:2020-6-4

    Now let’s take a look at the code of some sample programs The following example appears in the simple examples section def fact(n)       if n == 0            1       else            n * fact(n-1)       end end print fact(ARGV[0].to_i), “\n”   Because this is the first explanation, we will analyze line by line def fact(n)  In the first line, DEF is used to define a function (or, more […]

  • Ruby process control method

    Time:2020-6-3

    In this chapter, we will discuss more Ruby process control case As we can see, this is quite close to the switch of C and Java, but it is more powerful ruby> i=8 ruby> case i     | when 1, 2..5     |   print “1..5\n”     | when 6..10     |   print “6..10\n”     | end 6..10    nil  2.. 5 represents a range from 2 to 5. The following expression tests if I […]

  • How to use Ruby iterator

    Time:2020-6-2

    Iterator is not invented by Ruby. It is widely used in various object-oriented languages. It is also available in Lisp, but it is not so called. Nevertheless, the concept of iterator is not familiar to many people, so we will make a more detailed introduction here You know, the verb “iterate” means to do the […]

  • The concept of object-oriented thinking in Ruby

    Time:2020-5-31

    object-orientedIt’s a confusing phrase. It’s fashionable to call everything object-oriented. Ruby claims to be an object-oriented scripting language, but what is “Object-Oriented” We’ve got all kinds of answers, but all of them probably come down to the same thing. Instead of generalizing it quickly, let’s take a moment to think about traditional programming patterns In […]

  • Ruby single state method analysis

    Time:2020-5-25

    The behavior of an entity depends on its class, but many times we know that a specific entity needs a specific behavior. In many languages, we have to get into the trouble of defining another class, even if it is only used to materialize again. In ruby, we can assign any object to its own […]