Writing Module for Ruby

前端 未结 4 1012
走了就别回头了
走了就别回头了 2021-02-01 19:47

How do you write a module for ruby. in python you can use

# module.py
def helloworld(name):
    print \"Hello, %s\" % name

# main.py
import module
module.hell         


        
4条回答
  •  忘了有多久
    2021-02-01 20:43

    module NumberStuff 
      def self.random 
        rand(1000000) 
      end 
    end 
    
    module LetterStuff 
      def self.random 
        (rand(26) + 65).chr 
      end 
    end 
    
    puts NumberStuff.random 
    puts LetterStuff.random 
    

    184783
    X 
    

提交回复
热议问题