What are those pipe symbols for in Ruby?

前端 未结 7 755
一个人的身影
一个人的身影 2020-11-30 01:57

What are the pipe symbols for in Ruby?

I\'m learning Ruby and RoR, coming from a PHP and Java background, but I keep coming across code like this:

de         


        
7条回答
  •  难免孤独
    2020-11-30 02:06

    The equivalent in Java would be something like

    // Prior definitions
    
    interface RespondToHandler
    {
        public void doFormatting(FormatThingummy format);
    }
    
    void respondTo(RespondToHandler)
    {
        // ...
    }
    
    // Equivalent of your quoted code
    
    respondTo(new RespondToHandler(){
        public void doFormatting(FormatThingummy format)
        {
            format.html();
            format.xml();
        }
    });
    

提交回复
热议问题