require "rbs" require "pp" module RBS module Test module Hook OPERATORS = { :[] => "indexlookup", :[]= => "indexset", :== => "eqeq", :=== => "eqeqeq", :!= => "noteq", :+ => "plus", :- => "minus", :* => "star", :/ => "slash", :> => "gt", :>= => "gteq", :< => "lt", :<= => "lteq", :<=> => "ufo", :& => "amp", :| => "vbar", :^ => "hat", :! => "not", :<< => "lshift", :>> => "rshift", :~ => "tilda" } def self.alias_names(target) case target when *OPERATORS.keys name = OPERATORS[target] [ "#{name}____with__#{Test.suffix}", "#{name}____without__#{Test.suffix}" ] else aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 [ "#{aliased_target}__with__#{Test.suffix}#{punctuation}", "#{aliased_target}__without__#{Test.suffix}#{punctuation}" ] end end def self.setup_alias_method_chain(klass, target) with_method, without_method = alias_names(target) RBS.logger.debug "alias name: #{target}, #{with_method}, #{without_method}" klass.instance_eval do alias_method without_method, target alias_method target, with_method case when public_method_defined?(without_method) public target when protected_method_defined?(without_method) protected target when private_method_defined?(without_method) private target end end end def self.hook_method_source(prefix, method_name, key) with_name, without_name = alias_names(method_name) full_method_name = "#{prefix}#{method_name}" [__LINE__ + 1, <