Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
SyntaxSuggest.valid?
valid?(source)
lib/syntax_suggest/api.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/syntax_suggest/api.rb, line 211
def self.valid?(source)
!invalid?(source)
end
SyntaxSuggest.valid? [Private]
Returns truthy if a given input source is valid syntax
Example
SyntaxSuggest.valid?(<<~EOM) # => true def foo end EOM SyntaxSuggest.valid?(<<~EOM) # => false def foo def bar # Syntax error here end EOM
You can also pass in an array of lines and they’ll be joined before evaluating
Example
SyntaxSuggest.valid?( [ "def foo\n", "end\n" ] ) # => true SyntaxSuggest.valid?( [ "def foo\n", " def bar\n", # Syntax error here "end\n" ] ) # => false
As an FYI the CodeLine class instances respond to to_s so passing a CodeLine in as an object or as an array will convert it to it’s code representation.