Category:Ruby

  • 6 ways to invoke shell command in Ruby

    Time:2020-1-24

    When we need to call the operating system shell command, ruby provides us with six ways to complete the task: 1. Exec method: The kernel exec method replaces the current process example by calling the specified command: Copy codeThe code is as follows:       $ irb       >> exec ‘echo “hello $HOSTNAME”‘          hello nate.local […]

  • Detailed explanation of object-oriented programming in Ruby

    Time:2020-1-23

    Ruby is a pure object-oriented language, all projects seem to want Ruby as an object. Every value in ruby is an object, even the most primitive things: strings, numbers, even true and false. Even if a class itself is an object, it is an instance of a class. This chapter will cover Ruby’s object orientation […]

  • Detailed explanation of case expression in Ruby

    Time:2020-1-22

    Ruby’s case expressions have two forms: The first form is close to a set of sequential if statements: it lets you list a set of conditions and execute the statement corresponding to the first true condition expression. The second form specifies a target at the top of the case statement, and each when clause lists […]

  • Everything in ruby and metaprogramming is an object

    Time:2020-1-21

    Opening chapter Emptiness is color, and color is emptiness.In Ruby language, everything is an object. Ruby is an object-oriented language, and the concept of object-oriented is much stronger than other languages. There is no difference between primitive type data and object type data in Java in ruby. Most things in ruby are objects. So, to […]

  • Ruby array learning notes

    Time:2020-1-19

    1. Definition of array The array in ruby is a dynamic array. The data stored does not need to be limited in type. The length of the array is dynamically extended according to the storage needs. Therefore, when defining data, you can use the simplest way to new an array object. You can use the […]

  • Summary of variable learning in Ruby

    Time:2020-1-18

    There are several forms of variables in ruby, including local variables, instance variables, class variables, and global variables. For beginners, it’s easy to get confused, especially for those who do java like myself. After careful identification and learning, the differences and usage scenarios of these variables are summarized as follows: 1、 Naming method 1. Local […]

  • Summary of learning methods (functions) in Ruby

    Time:2020-1-17

    1. The naming rules of method name and variable name are the same in Ruby(Start with a lowercase letter, and use “,,” to separate words), but it can be followed by the method name! (weighing method) or? (boolean type return value). 2. Method, use (),Parameters are local variables. You can set default values for these […]

  • A summary of Ruby’s basic grammar learning

    Time:2020-1-16

    1. Keywords Keywords cannot be used to define variables or constants, such as module, class, def, undef, defined?, if, then, else, elsif, case, when, unless, for, in, while, until, next, break, do, redo, Retry, yield, not, and, or, true, false, nil, rescue, ensure, super, self, begin, end, begin, end, end, UU file_uuline_uu, return, alias 2, […]

  • Learning notes of string object in Ruby

    Time:2020-1-15

    1. String object definition The definition of string object can use ” and ”. For simple string, it is recommended to use ” for definition, which is more efficient than ”. ‘the difference between’ ‘and’ ‘is that the string in’ ‘is the final form after definition, even if it is like a line break, it […]

  • Learning notes of range object in Ruby

    Time:2020-1-14

    Range is a class of range objects. Range operators “..” or “…” can be used when defining. Range objects generated by “..” include start and end points. Range objects generated by “…” do not include start and end points. Range is composed of a sequence of ordered and regular element objects. Any group of ordered […]

  • An example of implementing Ruby declarative syntax

    Time:2020-1-13

    In activerecord, you can define the relationship between models in a very convenient way, for example: Copy codeThe code is as follows: class Topic < ActiveRecord::Base   has_many :posts   belongs_to :user end As a matter of fact, has many and belongs to are class methods of topic class. The standard writing method is: Copy […]

  • Configuration instance of accessing SQL Server database in Ruby

    Time:2020-1-12

    Because of the work needs, to analyze the data stored on SQL server, we have to study how to use ruby to access SQL server, and find that it is still very simple: Installing freetds Download freetds source code Decompress, compile and install: Copy codeThe code is as follows: ./configure –prefix=/usr/local/freetds && make && sudo […]