Sometimes we need to customize Ruby classes. I am going to introduce how to extend the Ruby Float class in simple steps.

As we are going to extend, create an extensions folder inside lib and create a float.rb inside this folder.

lib/extensions/float.rb

Now we need to initialize this module when application starts so that we can access this method in entire application. Create a file load_extensions.rb in initializers

config/initializers/load_extensions.rb

Now restart your server; that’s it. Now you can apply this with_precision() on float object anywhere in Application.

Click here for more details…

At BoTree Technologies, we build enterprise applications with our RoR team of 25+ engineers.

We also specialize in Python, RPA, AI, Django, JavaScript and ReactJS.

Consulting is free – let us help you grow!