Ruby performance: define method with define_method or eval -


while looking through activesupport source code i've noticed eval used in places define_method enough.

example: activesupport: module.delegate

i consider define_method more clean , safe way of doing things. benefits of eval on define_method? perfomance, memory usage, else?

when use define_method, method you're defining can't accept block.

it’s pretty known because of deficiency in blocks arguments in ruby 1.8 class#define_method cannot define methods take blocks.

def x *args, █ end  # => works! define_method(:x) {|*args,&block| } # => syntaxerror: compile error 

the method being defined requires block:

"def #{prefix}#{method}(*args, &block)" # def customer_name(*args, &block) 

so define_method can't used.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -