All your Base are belong to us
Tags:
github
ruby
“The universal base class you always wanted”, from Gary Bernhardt.
From the lib:
def self.call_method(object, name, args, block)
name_string = name.to_s
all_modules.each do |mod|
if mod.respond_to?(name)
return mod.send name, *args, &block
elsif mod.instance_methods.include?(name_string)
return call_instance_method(mod, name, args, block)
end
end
# 1. The world is all that is the case.
# 2. We failed to find a method to call.
# 2.1. So we need to call method_missing.
# 2.1.1. We can't just super it because we're not in method_missing.
# 2.1.1.1. We're not in method_missing because there are two of them
# (self and instance) that need to share this code.
# 2.1.1.2. We need to call the method that would be called if we said
# "super" in the object's method_missing.
# 2.1.1.2.1. Which is its class's superclass's method_missing method
# object.
Object.instance_method(:method_missing).bind(object).call(name, *args, &block)
end
A base class that makes all instance methods, class methods, and constants of any classes available directly within the class.
aheemmm
10 notes ()
-
reparatiifrigidere liked this
-
michael-sokol reblogged this from thechangelog and added:
makes all instance methods, class methods,...constants of any classes available directly...
-
ecleel liked this
-
nateberkopec liked this
-
andion liked this
-
tantsy reblogged this from thechangelog and added:
This looks like cheem CS1010E
-
thechangelog posted this
