Here's good place to use a unary operator:
```ruby
valid_datatype?(val) ? RDF::Literal(val) : val
```