Sha256: 7ff1fc7f7391efa0673184783b753af713f0a389d66e9621daf219d96c047ff2

Contents?: true

Size: 1006 Bytes

Versions: 6

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

class SingletonMethod
  class << self
    def say_default
      'default'
    end
  end

  def SingletonMethod.say_class_defined
    'defined with explicit class scope'
  end

  def self.say_self_defined
    'defined with self class scope'
  end

  # When called, do_include calls +include+ to bring in the module
  # AddMethod. AddMethod defines a new instance method, which gets
  # added to the singleton class of SingletonMethod.
  def do_include
    class << self
      SingletonMethod.include(AddMethod)
    end
    self
  end
  
  def self.new_with_instance_method
    SingletonMethod.new.tap do |m|
      def m.say_instance_defined
        'defined for an instance'
      end
    end
  end
  
  def to_s
    'Singleton Method fixture'
  end
end

module AddMethod
  def self.included(base)
    base.module_eval do
      define_method "added_method" do
        _added_method
      end
    end
  end
  
  def _added_method
    'defined by including a module'
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
appmap-0.34.1 spec/fixtures/hook/singleton_method.rb
appmap-0.34.0 spec/fixtures/hook/singleton_method.rb
appmap-0.33.0 spec/fixtures/hook/singleton_method.rb
appmap-0.32.0 spec/fixtures/hook/singleton_method.rb
appmap-0.31.0 spec/fixtures/hook/singleton_method.rb
appmap-0.28.1 spec/fixtures/hook/singleton_method.rb