synvert-core-ruby icon indicating copy to clipboard operation
synvert-core-ruby copied to clipboard

Runtime manipulations

Open SandNerd opened this issue 9 years ago • 2 comments

What a hidden gem! I'm pretty interested into using this for meta programming. I realize that, as it is, it's not targeted for that but I was wondering if this is something that you'd like to consider.

SandNerd avatar Oct 23 '16 00:10 SandNerd

@sahal2080 what's your expectation? could you give me some pseudo-code examples?

flyerhzm avatar Oct 23 '16 12:10 flyerhzm

A bit of context to help clarify, the end goal would be to:

Enable dynamic reuse/re-purpose of partials of code within public (gems) or private projects, by fetching, patching and then embedding the partials within new code dynamically.

To give you a concrete example, I'm working on a gem with the goal of dynamically converting any core-extension out there into a refinement. Core extensions as refinements are beautifully illustrated in this existing gem, My issue with it is that addition of any core extension has to be done manually.

The code I have currently can fetch and convert simple extensions, e.g. this, into refinements (using lots of regex). However, when dealing with more hairy stuff, it fails.

Regarding an expectation, maybe something like this

Synvert::Rewriter.*something*(source_cord_string_or_node, 'core_ext_refinements', 'wrap_core_class') do
 # add / replace / remove code
end

This of course expects that the method will return an ast node or source code. I have a preference (and this is an overall suggestion for Synvert) for returning nodes instead of code. The benefit would be the ability to write more atomic synvert snippets and be able to simply stitch them together to create a larger snippet. This, admittedly, will serve my purpose more 😁 but I also think it'll make it easier to contribute and share snippets and grow the synvert snippets repo.

SandNerd avatar Oct 23 '16 15:10 SandNerd