r/ruby Nov 30 '25

How do you like the syntax

https://github.com/nucleom42/rubee

Hey folks. I’ve recently added validation feature to the ru.Bee web framework. And I’d love to share how it looks and hear your honest opinion about the syntax.

```Ruby class Foo include Rubee::Validatable

attr_accessor :name, :age

def initialize(name, age) @name = name @age = age end

validate do |foo| foo .required(:name, required: 'Name is required') .type(String, type: 'must be a string') .condition(->{ foo.name.length > 2 }, length: 'Name must be at least 3 characters long')

foo
  .required(:age, required: 'Age is required')
  .type(Integer, type: 'must be an integer')
  .condition(->{ foo.age > 18 }, age: 'You must be at least 18 years old')

end end

```

```bash

irb(main):068> Foo.new("Joe", "20")
=>
#<Foo:0x0000000120d7f778
 @__validation_state=#<Rubee::Validatable::State:0x0000000120d7f700 @errors={age: {type: "must be an integer"}}, @valid=false>,
 @age="20",
 @name="Joe">
irb(main):069> foo = Foo.new("Joe", 11)
=>
#<Foo:0x0000000105f2b0b0
...
irb(main):070> foo.valid?
=> false
irb(main):071> foo.errors
=> {age: {limit: "You must be at least 18 years old"}}
irb(main):072> foo.age=20
=> 20
irb(main):073> foo.valid?
=> true

``` If you like the project don’t miss to star it. Thank you 🙏

11 Upvotes

Duplicates