Last active
December 22, 2015 11:19
-
-
Save apeiros/6465148 to your computer and use it in GitHub Desktop.
class_* convenience variants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def class_call(*args, &block) | |
self.class.__send__(caller_locations(1,1).first.label, *args, &block) | |
end | |
def class_method(name=caller_locations(1,1).first.label) | |
self.class.method(name) | |
end | |
def class_send(name=caller_locations(1,1).first.label, *args, &block) | |
self.class.__send__(name, *args, &block) | |
end | |
end | |
class Foo | |
def self.bar | |
"bar" | |
end | |
def bar | |
class_call | |
end | |
def baz | |
class_method(:bar) # -> #<Method> | |
end | |
def quuz | |
class_send(:bar) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment