Skip to content

Instantly share code, notes, and snippets.

@apotterri
Last active July 16, 2020 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apotterri/5dbe76a39d2af565facc84e3b49049a2 to your computer and use it in GitHub Desktop.
Save apotterri/5dbe76a39d2af565facc84e3b49049a2 to your computer and use it in GitHub Desktop.
appmap before and after
5dbe76a39d2af565facc84e3b49049a2
name: appland/singleton methods
packages:
- path: test.rb
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '~> 2.6'
gem 'appmap', '~> 0.28.0',
git: 'https://github.com/applandinc/appmap-ruby',
branch: 'master'
module AddMethod
def self.included(base)
base.module_eval do
define_method 'new_method' do
"it's a new method"
end
end
end
end
class Foo
def self.static_method
"it's a static method"
end
def do_include
$stderr.puts singleton_class.ancestors.inspect
Foo.include AddMethod
$stderr.puts singleton_class.ancestors.inspect
end
end
Foo.static_method
f = Foo.new
f.do_include
f.new_method
class Bar
def do_include
class << self
$stderr.puts ancestors.inspect
include AddMethod
$stderr.puts ancestors.inspect
end
end
end
b = Bar.new
b.do_include
b.new_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment