You [Gerald Bauer¹] have been permanently banned [for life] from participating in r/ruby (because of your writing off / outside of r/ruby). I do not see your participation adding anything to this [ruby] community.

-- Richard Schneeman (r/ruby mod and fanatic illiberal ultra leftie on a cancel culture mission)

¹: I know. Who cares? Who is this Gerald Bauer anyway. A random nobody for sure. It just happens that I am the admin among other things of Planet Ruby.

Case Studies of Code of Conduct "Cancel Culture" Out-Of-Control Power Abuse - Ruby - A Call for Tolerance On Ruby-Talk Results In Ban On Reddit Ruby

Update (August, 2022) - A Call for More Tolerance And Call For No-Ban Policy Results In Ban On Ruby-Talk (With No Reason Given)

>  I just banned gerald.bauer@gmail.com.
>
>  -- SHIBATA Hiroshi
>
>> THANK YOU
>> 
>>  -- Ryan Davis
>>
>>
>> My full support to moderators.
>>
>> -- Xavier Noria
>> 
>> My full support to moderators.
>>
>>  -- Carlo E. Prelz
>>
>>  That's fun.
>>
>>  -- Alice

Read the full story »


« 25 Days of Ruby Gems - Ruby Advent Calendar 2020, December 1st - December 25th

Day 18 - dentaku Gem - Parse and Evaluate Math (and Logical Formulas) with a Calculator in a Sandbox, Safely

Written by jankeesvw Jankees van Woezik

A freelance full stack maker from the Netherlands with a love for building products. Co-founder of Stekker.app and Timi.app.

Evaluate math and logical formulas

This gem is not something you need for every project, but it’s a fun one.

I’m building a Ruby on Rails app for Stekker.app. Creating invoices for charging sessions of electric vehicles is one of the things we do. Every customer can have a different contract and those contracts can have different pricing structures.

For instance, this is one of our formulas:

minutes * costPerMinute + kwhVolume * costPerKwh

You probably wonder how that evaluates to a price for a charging session?

Enter Dentaku

Dentaku means calculator in Japanese, and that’s exactly what this gem does. The readme has some great examples and I’ll share some here so you see what it can do.

Let’s start with a simple example:

calculator = Dentaku::Calculator.new
calculator.evaluate('10 * 2')
#=> 20

Okay, that’s not hard and you could do the same with eval in plain Ruby (please don’t it’s unsafe!). Dentaku can do so much more, take this example:

calculator = Dentaku::Calculator.new
calculator.evaluate('kiwi + 5', kiwi: 2)
#=> 7

So yes, it can handle variables, now take a look at even a more complex example:

calc = Dentaku::Calculator.new
calc.store(monthly_income: 50)
need_to_compute = {
  annual_income: "monthly_income * 12",
  income_taxes:  "annual_income / 5"
}
calc.solve!(need_to_compute)
#=> { annual_income: 600, income_taxes: 120 }

We have been using this gem since last year and it has been rock solid!

Find Out More

I encourage you to checkout the Readme, it has some great examples of things you can do with Dentaku.

References

Built with Ruby (running Jekyll) on 2023-01-25 18:05:39 +0000 in 0.371 seconds.
Hosted on GitHub Pages. </> Source on GitHub. (0) Dedicated to the public domain.