Home
The Ruby code Query and Manipulation Language (Ruby QML) is a DSL for querying, traversing and manipulating Ruby code.
Ruby QML is a language for accessing and manipulating Ruby code, much like SQL is a language for accessing and manipulating tables in a database.
Ruby QML consists of two distinct APIs
- Ruby code Query Language (Ruby QL)
- Ruby code Manipulating Language (Ruby ML)
See Query API for more details.
- find(type, …)
- inside(type, …) do |node|
The method inside is merely an alias for find which requires a block argument.
Note a block argument can also be given for find.
The argument type is a symbol indicating the Node type to find.
There is currently support for finding the following Node types:
- :module
- :class
- :variable
- :assignment
- :call
- :block
- :def (or :method)
Ruby Nodes that you find using the Ruby QL can be manipulated using the Ruby ML.
See Manipulation API for more details.
Manipulation commands supported on Ruby nodes:
- insert
- update
- delete
- insert(:before, code)
- insert (:after, code)
- update(:select => {…}, :with => {..}, &block)
- update(:select => {…}, :with_code => ‘…’, &block)
For assignment nodes (fx b = 7)
- update(:value, &block)
- delete
See test directory for more detailed examples of use.