5 ms·
That's such an edge case. I've never seen anybody defining functions in evals, especially as concatenated strings.
by rorrr 15y ago
That's such an edge case. I've never seen anybody defining functions in evals, especially as concatenated strings.
- agento 15y agoMaybe you should take a look at the Rails sourcecode.
- FooBarWidget 15y agoRails only does that to optimize certain function calls. eval() is used as a method to compile/inline certain functions. Most code in Rails does not use eval.
- drothlis 15y agohttps://github.com/rails/rails/blob/2-3-stable/actionpack/lib/action_controller/request.rb#L11 https://github.com/rails/rails/blob/2-3-stable/actionpack/li... Try getting your editor to find that definition of method "accept_language" or "cache_control". :-)
- TylerE 15y agoI've done it. Use case involves a class wrapping python's xml-rpc stuff to talk to Drupal. Drupal's xml-rpc interface is not the most pleasant thing to work with, as you have to pass in a session id and auth token on every request, and then all the "actual" parameters go in as an array. My wrapper class would query the remote interface for available methods, and then dynamically generate, via eval, a function object that used a closure to store the sess/auth tokens, and that took a variable number of arguments to pass as the 3rd array argument to the function. The eval'd function object was then bound as a method to the connection object. It also did a bit more magic, such as on error logging the arguments to a file. ALl in all it made writing web-service clients a lot more pleasant.