Skip to content

Commit

Permalink
Add User definition to example (close #459)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent b5bc71d commit 89d0eba
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docsite/source/custom-types.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ valid[:invalid]
`Types.Constructor` builds a new constructor type for the given class. By default uses the `new` method as a constructor.

```ruby
class User
def initialize(attributes)
@attributes = attributes
end

def name = @attributes.fetch(:name)
end

user_type = Types.Constructor(User)

# It is equivalent to User.new(name: 'John')
Expand Down Expand Up @@ -93,4 +101,4 @@ ListOfStrings = Types.Array(Types::String)
```ruby
Callable = Types.Interface(:call)
Contact = Types.Interface(:name, :phone)
```
```

0 comments on commit 89d0eba

Please sign in to comment.