Load dry-rb gems with Rails


I am trying to use dry-rb gems, specifically dry-monads on Ruby on Rails project (version I add the next line in my Gemfile:

source 'https://rubygems.org'
#Another gems
gem 'dry-monads'

Execute bundle install command and it is successful. However when I try to include Dry::Monads[:result] and load the class, the rails console throws the next error:

NameError (uninitialized constant MyNamespace::MyClass::Dry.

I also try to include Dry::Monads::Result::Mixin instead Dry::Monads[:result] and rails console throws the same error.

If I try require explicitly the console throws LoadError (cannot load such file – dry/monads).

Do you have any idea about this problem?

Thanks in advance and regards.

Really hard to tell what’s going on there. I can only say require 'dry/monads' at the top of a file where you reference Dry::Monads should do it. I don’t think rails breaks it. If you can provide a standalone reproducible example I’ll be able to figure this out (well, I usually do!).

1 Like