Class: Prettyrb::Formatter
- Inherits:
-
Object
- Object
- Prettyrb::Formatter
- Defined in:
- lib/prettyrb/formatter.rb
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(code) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(code) ⇒ Formatter
Returns a new instance of Formatter.
5 6 7 |
# File 'lib/prettyrb/formatter.rb', line 5 def initialize(code) @code = code end |
Instance Method Details
#format ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prettyrb/formatter.rb', line 9 def format parser = Parser::CurrentRuby.new(Prettyrb::Builder.new) parser.diagnostics.all_errors_are_fatal = true parser.diagnostics.ignore_warnings = true parser.diagnostics.consumer = lambda do |diagnostic| $stderr.puts(diagnostic.render) end root_node, _comments = parser.parse_with_comments( Parser::CurrentRuby.send(:setup_source_buffer, "file='(string)'", 1, @code, parser.default_encoding) ) visitor = Visitor.new(root_node) visitor.visit(root_node) visitor.output end |