-
Notifications
You must be signed in to change notification settings - Fork 16
Converting between RBI and RBS
Aaron Christiansen edited this page Sep 13, 2020
·
1 revision
You can convert a tree of type information between Parlour's formats. This means that you can write code to generate RBI files, and then use a converter to also get an RBS file describing the same types.
Conversions are usually lossy. RBI and RBS come from two very different type systems and it isn't possible to express many of one's concepts in the other. You'll get warnings printed if a significantly lossy operation occurs, such as:
- A node and its children being entirely dropped because it isn't supported in the target type system.
- A node being converted one-way into a close equivalent on the target type system (such as an RBI struct being converted to an equivalent RBS class).
Currently, only converting RBI to RBS is supported.
- If you're using legacy string types, rather than
Parlour::Types
types, convert your type tree to useParlour::Types
types withNamespace#generalize_from_rbi!
. - Create a
Parlour::RbsGenerator
to insert the converted nodes into. - Create a
Parlour::Conversion::RbiToRbs
converter instance. - Call
#convert_all
, passing the root of the RBI namespace to convert from, and the root of the RBS tree to add new children to.
Here's a code example:
rbi_gen = Parlour::RbiGenerator.new
# ...create some types...
# 1. If you used string types...
rbi_gen.root.generalize_from_rbi!
# 2. Create a new RBS generator
rbs_gen = Parlour::RbsGenerator.new
# 3. Create a converter
converter = Parlour::Conversion::RbiToRbs.new(rbs_gen)
# 4. Perform the conversion
converter.convert_all(rbi_gen.root, rbs_gen.root)