Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'main' of https://github.com/joeldrapper/literal

+8 -2
+8 -2
README.md
··· 152 152 153 153 ### `_Class(T)` 154 154 155 - The `_Class` type ensures the given value is a calss and subclasses the given `T` class. 155 + The `_Class` type ensures the given value is a class and subclasses the given `T` class. 156 156 157 157 ```ruby 158 158 attribute :error, _Class(RuntimeError) ··· 174 174 attribute :degrees _Float(0..360) 175 175 ``` 176 176 177 - You can also compose these types together to form more complex types. 177 + You can also compose these types together to form more complex types. You can also save your own types as constants for re-use. 178 + 179 + ```ruby 180 + AttributeType = Literal::Types::_Union(String, Symbol, Literal::Types::_Interface(:to_s)) 181 + ``` 182 + 183 + Note unless you've extended `Literal::Types`, you'll need to reference the types by their fully qualified names. These types are methods, so why are we accessing them with `::`? It's a little known fact that `::` can stand in for `.` in Ruby. I like using `::` here becuase it makes these look more like normal generics. If you prefer, you can use `.`, e.g. `Literal::Types._Interface(:to_s)`. 178 184 179 185 ## Writing your own type matchers 180 186