Skip to content
Parse YARD type strings and type check objects against them
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Gem Version Build Status Dependency Status Code Climate Coverage Status Inline docs

Parse YARD type description strings -- eg Array<#to_sym> -- and use the resulting types to check type correctness of objects at runtime.


Like everything else these days:

gem 'yard_types'

Note that the yard gem may automatically require anything named yard_* or yard-* on your load path, and attempt to use it as a plugin. You could see errors along the lines of failed to load plugin yard_types; this is harmless, as best I can tell.


Parse a type description string, and test an object against it:

type = YardTypes.parse('#quack') #=> #<YardTypes::TypeConstraint ...>

#=> false

obj =
def obj.quack; 'quack!'; end
#=> true


YARD does not officially specify a syntax for its type descriptions; the syntax used by its own documentation varies between files. The syntax supported in this gem aims to follow the rules given by the YARD Type Parser.

In the wild, people seem to use a wide variety of different syntaxes, many of which are unlikely to be supported right now. If you find any such examples, feel free to file an issue -- or better yet, write a test, implement the feature, and send me a pull request.


Pretty standard. Just run rake or rspec.


  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


The bulk of the parser was written by lsegal; unfortunately, it was never released as a gem, and has sat untouched for 5 years. I've only modified the parser to better support Hash<A, B> syntax and to use more consistent naming patterns.

You can’t perform that action at this time.