Ruby: How to make a public static method?

前端 未结 4 1865
醉梦人生
醉梦人生 2021-02-01 12:15

In Java I might do:

public static void doSomething();

And then I can access the method statically without making an instance:

c         


        
4条回答
  •  抹茶落季
    2021-02-01 12:44

    Your given example is working very well

    class Ask
      def self.make_permalink(phrase)
        phrase.strip.downcase.gsub! /\ +/, '-'
      end
    end
    
    Ask.make_permalink("make a slug out of this line")
    

    I tried in 1.8.7 and also in 1.9.3 Do you have a typo in you original script?

    All the best

提交回复
热议问题