class Rage::Internal
@private
def build_arguments(method, arguments)
-
(String)- the string representation of the method arguments
Parameters:
-
arguments(Hash) -- the arguments to include in the string representation -
method(Method, Proc) -- the method to build arguments for
def build_arguments(method, arguments) expected_parameters = method.parameters arguments.filter_map { |arg_name, arg_value| if expected_parameters.any? { |param_type, param_name| param_name == arg_name || param_type == :keyrest } "#{arg_name}: #{arg_value}" end }.join(", ") end
def define_dynamic_method(klass, block)
-
(Symbol)- the name of the newly defined method
Parameters:
-
block(Proc) -- the implementation of the new method -
klass(Class) -- the class to define the method in
def define_dynamic_method(klass, block) name = dynamic_name_seed.next.join klass.define_method("__rage_dynamic_#{name}", block) end
def define_maybe_yield(klass, method_name)
-
(Symbol)- the name of the newly defined method
Parameters:
-
method_name(Symbol) -- the method to call if the condition is `true` -
klass(Class) -- the class to define the method in
def define_maybe_yield(klass, method_name) name = dynamic_name_seed.next.join klass.class_eval <<~RUBY, __FILE__, __LINE__ + 1 def __rage_dynamic_#{name}(condition) if condition #{method_name} { yield } else yield end end RUBY end
def dynamic_name_seed
def dynamic_name_seed @dynamic_name_seed ||= ("a".."j").to_a.permutation end