Can I invoke an instance method on a Ruby module without including it?

前端 未结 10 1324
情歌与酒
情歌与酒 2020-12-07 07:37

Background:

I have a module which declares a number of instance methods

module UsefulThings
  def get_file; ...
  def delete_file; ...

  def forma         


        
10条回答
  •  旧巷少年郎
    2020-12-07 07:54

    I think the shortest way to do just throw-away single call (without altering existing modules or creating new ones) would be as follows:

    Class.new.extend(UsefulThings).get_file
    

提交回复
热议问题