explaingit

solnic/virtus

Analysis updated 2026-07-03

3,747RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

Virtus is a discontinued Ruby library that adds typed, auto-coercing attributes to plain Ruby objects, converting strings to integers or dates automatically. The author now recommends dry-types as the modern replacement.

Mindmap

mindmap
  root((Virtus))
    What it does
      Typed Ruby attributes
      Automatic type coercion
      Attribute declaration
    Features
      Default values
      Nested object attributes
      Typed collections
      Optional module config
    Use Cases
      Web form sanitization
      JSON to domain objects
      Value objects
    Status
      Discontinued
      Replaced by dry-types
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Map incoming JSON API response data to a Ruby domain object with typed fields without writing manual conversion code

USE CASE 2

Sanitize and coerce web form parameters into the correct types before processing them in a Rails controller

USE CASE 3

Build a Ruby value object with a typed collection attribute such as an array of address objects with enforced types

What is it built with?

Ruby

How does it compare?

solnic/virtuslaserlemon/figarofeedbin/feedbin
Stars3,7473,7483,745
LanguageRubyRubyRuby
Setup difficultyeasyeasyhard
Complexity2/51/54/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Project is discontinued, new projects should use dry-types and dry-struct instead as the author recommends.

In plain English

Virtus is a Ruby library that lets you add typed attributes to plain Ruby objects. Normally, a Ruby class has no built-in way to say "this field should be an integer" or "this field should be a date" and have that enforced automatically. Virtus fills that gap by giving you a clean way to declare attributes with specific types, and it will automatically convert incoming values to match those types when possible. For example, if you define an attribute as an integer and someone passes in the string "31", Virtus converts it to the number 31 without you having to write any conversion code. The same logic applies to dates: pass in a date string and get back a proper date object. This is useful any time data arrives from outside your program, such as from a web form, a JSON response, or a configuration file. The library also supports default values, nested objects (where one attribute is itself another Virtus-backed object), and typed collections (an array of integers, or an array of address objects). You can control which features are active: constructor generation, mass assignment, and type coercion can each be turned on or off independently. The README prominently states that Virtus is discontinued. The author, having learned from building it, went on to create a set of successor libraries called dry-types, dry-struct, and dry-schema, which handle the same problems with a cleaner design. Anyone starting a new project is directed to those replacements instead. For projects that already use Virtus and have not yet migrated, the library still functions as documented. Its original use cases included sanitizing and coercing input parameters in web applications, mapping JSON data to domain objects, building value objects, and prototyping data models. The gem is available through the standard Ruby package registry.

Copy-paste prompts

Prompt 1
Using Virtus, show me how to define a Ruby class with typed attributes for name as string, age as integer, and birthday as date, so that passing a string like '31' automatically converts it to an integer.
Prompt 2
How do I use Virtus to map a JSON API response hash to a Ruby object with nested typed attributes, for example a User that has an Address attribute?
Prompt 3
I need to migrate an existing project from Virtus to dry-types. What are the key differences and how do I convert a Virtus model to a dry-struct?
Prompt 4
Show me how to configure a Virtus model to turn off mass assignment but keep automatic type coercion enabled, using the module options.

Frequently asked questions

What is virtus?

Virtus is a discontinued Ruby library that adds typed, auto-coercing attributes to plain Ruby objects, converting strings to integers or dates automatically. The author now recommends dry-types as the modern replacement.

What language is virtus written in?

Mainly Ruby. The stack also includes Ruby.

How hard is virtus to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is virtus for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub solnic on gitmyhub

Verify against the repo before relying on details.