• Using bundler to manage multiple versions of gem installed in Ruby environment


    With rbenv to manage the multi version Ruby environment, we also need a tool that can manage multi version gems (such as rails), that is, bundler. The project background will not be described in detail. What we need to know is directly to the official website http://bundler.io/ , here are just some practical experience. install […]

  • Explain singleton methods and singleton classes in Ruby


    singleton method Ruby allows you to add methods to a single object. This method that works only for a single object is called a singleton method Sample code ? 1 2 3 4 5 6 7 8 9 10 11 12 str = “just a regular string”   def str.title?   self.upcase == self end   […]

  • An example explains the hook method in ruby and adding hooks to method calls


    The hook method is similar to the event driven device. It can execute a specific callback function after a specific event occurs. This callback function is the hook method (more vividly: the hook method can hook a specific event like a hook). In rails, the before \ after function is the most common hook method. […]

  • Application example analysis of hook method in Ruby


    By using the hook method, we can intervene in the life cycle of ruby classes or modules, which can greatly improve the flexibility of programming.Hook methods related to life cycle are as follows: Class is module dependent Class#inherited Module#include Module#prepended Module#extend_object Module#method_added Module#method_removed Module#method_undefined Single piece related BasicObject#singleton_method_added BasicObject#singleton_method_removed BasicObject#singleton_method_undefined Sample code ? 1 2 […]

  • Ruby implements insertion sorting algorithm and advanced two-way insertion sorting code example


    BasicsInsert a record into a sorted table to get an ordered table with one record added. And the most critical point is that it moves all records larger than the current element back to make room for “itself” to be inserted. When the N-1 insertion is completed, the record is an ordered sequence. ? 1 […]

  • Summary of basic operation methods of hash type in Ruby


    1. Create hash:Just like creating arrays, we can create a hash instance through the hash class: ? 1 2 h1 = Hash.new             #The default value is nil h2 = Hash.new(“This is my first hash instance”) #The default value is “this is my first hash instance”: Both of the above examples create an empty hash instance. […]

  • Summary of syntax and language features of ruby


    Ruby is an interpreted, object-oriented, dynamically typed language. Ruby’s strategy is to find a balance between flexibility and runtime security. With the emergence of rails framework, ruby became a blockbuster around 2006, and also guided people to regain the fun of programming. Although ruby is not very efficient in terms of execution speed, it can […]

  • Summary of basic operation methods of hash structure in Ruby


    About hashLet’s first understand the basic idea of hash:Set the number of objects to be stored as num, then we use len memory units to store them (len > = Num); Take the keyword of each object ki as the argument, use a function H (KI) to reflect the memory address of Ki, that is, […]

  • Simple example of binary search (binary search) algorithm implemented by ruby


    In computer science, binary search, also known as half interval search and logarithmic search, is a search algorithm for finding a specific element in an ordered array. The search process starts from the middle element of the array. If the middle element is exactly the element to be found, the search process ends; If a […]

  • Ruby regular expression explanation and sample code


    Many Ruby regular expressions are used in writing the PP file of puppet. The common regular expressions are as follows: Regular expression: [codesyntax lang=”ruby“] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 {}: number of repetitions (e.g{4}Indicates that the previous will repeat4(Times) {m, n}: the previous […]

  • Image filter algorithm code implemented by ruby


    Original drawing 1、 Gray algorithm The color value of each pixel in a color photo is a mixture of red, green and blue values. The values of red, green and blue are different, so the color value of the pixel can also have many color values, which is colorpictureThe general processing method is to set […]

  • Detailed steps for installing Ruby running environment under Mac OS X


    preface Ruby is a powerful object-oriented scripting language. It integrates the characteristics of Perl, python, Java and other languages. It has strong word processing ability, simple syntax, and is completely object-oriented. At the same time, ruby is an interpretive language, which can be programmed quickly without compilation. For new developers, how to install Ruby and […]