vadviktor
11/3/2015 - 10:38 AM

Ruby: how to create a module that will include class and instance variants of the same method

Ruby: how to create a module that will include class and instance variants of the same method

require_relative 'helper'

class Useme

  include Helper

  def instme
    info
  end

  class << self
    def classme
      info
    end
  end

end

# use 
Useme::classme
Useme.new.instme
module Helper
  def self.included base
    base.send :include, InstanceMethods
    base.extend ClassMethods
  end

  module InstanceMethods
    def info
      self.class.info
    end
  end

  module ClassMethods
    def info
      puts 'putting out info here'
    end
  end

end