Skip to content

Instantly share code, notes, and snippets.

@apeiros
Last active December 22, 2015 11:19
Show Gist options
  • Save apeiros/6465148 to your computer and use it in GitHub Desktop.
Save apeiros/6465148 to your computer and use it in GitHub Desktop.
class_* convenience variants
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