Skip to content

Instantly share code, notes, and snippets.

@ota42y
Last active March 16, 2017 06:50
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 ota42y/afa18467d21d97b32ceb761a636fe032 to your computer and use it in GitHub Desktop.
Save ota42y/afa18467d21d97b32ceb761a636fe032 to your computer and use it in GitHub Desktop.
begin
require "bundler/inline"
rescue LoadError => e
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "activesupport"
end
require "active_support"
module A
extend ActiveSupport::Concern
included do
echo_method :a_class_echo_method_in_includes
def method_abc
puts 'abc'
puts test_class_echo_method
puts test_class_instance_method
puts a_class_echo_method_in_includes
puts self.test_class_class_method
end
end
# not work
# echo_method :a_class_echo_method_outside_includesp
def method_xyz
puts 'xyz'
puts test_class_echo_method
puts test_class_instance_method
puts self.test_class_class_method # error
end
end
module AddTestName
def echo_method(echo_str)
class_eval <<-RUBY
def #{echo_str}
'#{echo_str}'
end
RUBY
end
end
class Test
extend ::AddTestName
include A
echo_method :test_class_echo_method
def test_class_instance_method
'test_class_instance_method'
end
def self.test_class_class_method
'test_class_class_method'
end
end
t = Test.new
t.method_abc
t.method_xyz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment