Last active
February 2, 2018 00:11
-
-
Save zeisler/1470ca53344e3a93e72c7af980bb19d0 to your computer and use it in GitHub Desktop.
Converts Object.new(<args>).call to Object.call(<args>)
This file contains 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
require "reverse_parameters" | |
# Converts Object.new(<args>).call to Object.call(<args>) | |
# module must be extend after initialize method in order to transfer parameters | |
module CallObject | |
def create_callable | |
class_eval(<<-RUBY, __FILE__, __LINE__ + 1) | |
def self.call(#{ReverseParameters.new(instance_method(:initialize)).parameters}) | |
self.new(#{ReverseParameters.new(instance_method(:initialize)).arguments}).call | |
end | |
RUBY | |
end | |
def self.extended(base) | |
base.create_callable | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment