What does :: do?

前端 未结 5 1685
南旧
南旧 2020-12-16 23:18

I have some inherited code that I am modifying. However, I am seeing something strange(to me).

I see some code like this:

::User.find_by_email(params         


        
5条回答
  •  离开以前
    2020-12-16 23:58

    The "::" operator is used to access Classes inside modules. That way you can also indirectly access methods. Example:

    module Mathematics
        class Adder
           def Adder.add(operand_one, operand_two)
               return operand_one + operand_two
           end
        end
    end
    

    You access this way:

    puts “2 + 3 = “ + Mathematics::Adder.add(2, 3).to_s
    

提交回复
热议问题