Sha256: edee7bf23faaeb1c5789ef7abcd8b33d109131af21a0b05479c9b607f784eb33

Contents?: true

Size: 948 Bytes

Versions: 19

Compression:

Stored size: 948 Bytes

Contents


require 'Yk/__hook__'

module MissingMethod
	def initialize_missing_method o, m
		@obj__ = o
		@method__ = m
	end
	def call *args, **opts, &bl
		if @method__ =~ /[^a-zA-Z0-9_?]/ && !bl && args.size <= 1 && opts.size == 0
			if args.size == 1
				eval("@obj__ #{@method__} args[0]")
			elsif args.size == 0
				eval("#{@method__} @obj__")
			end
		else
			eval("@obj__.#{@method__}(*args, **opts, &bl)")
		end
	end
	def [] *args
		call *args
	end
	def arity
		raise NotImplementedError.new("MissingMethod#arity is not implemented")
	end
	def unbind
		raise NotImplementedError.new("MissingMethod#unbound is not implemented")
	end
end


class Object
	alias_method :method_____, :method
	def method (n)
		begin
			method_____(n)
		rescue NameError
			prx = method_____(:__id__)
			prx.extend MissingMethod
			prx.initialize_missing_method self, n
			prx.__hook__ :inspect do |org|
				org.call.sub(/#[^#]+$/, "##{n}")
			end
			prx
		end
	end
end


Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
YkLib-0.1.8.9 lib/Yk/missing_method.rb
YkLib-0.1.8.8 lib/Yk/missing_method.rb
YkLib-0.1.8.7 lib/Yk/missing_method.rb
YkLib-0.1.8.6 lib/Yk/missing_method.rb
YkLib-0.1.8.5 lib/Yk/missing_method.rb
YkLib-0.1.8.4 lib/Yk/missing_method.rb
YkLib-0.1.8.3 lib/Yk/missing_method.rb
YkLib-0.1.8.2 lib/Yk/missing_method.rb
YkLib-0.1.8.1 lib/Yk/missing_method.rb
YkLib-0.1.8 lib/Yk/missing_method.rb
YkLib-0.1.7.1 lib/Yk/missing_method.rb
YkLib-0.1.7 lib/Yk/missing_method.rb
YkLib-0.1.6 lib/Yk/missing_method.rb
YkLib-0.1.5 lib/Yk/missing_method.rb
YkLib-0.1.4 lib/Yk/missing_method.rb
YkLib-0.1.3 lib/Yk/missing_method.rb
YkLib-0.1.2 lib/Yk/missing_method.rb
YkLib-0.1.1 lib/Yk/missing_method.rb
YkLib-0.1.0 lib/YkLib/Yk/missing_method.rb