I made this Korean numbers converter:
Check it out here:
The task is originally from a coding challenge for a company in Seoul which I solved in my favorite language Ruby, and I thought it’s worth making a little app out of it. I really like Ruby, it’s fun to write and just makes sense looking at it. The less curly brackets the better, IMO. The less ceremony, the less confusion. So many people, coming from darker places like myself, rediscovered the joy of creating things with code trough Ruby, it definitely made the world a better place for programmers.
The app I made was done in Ruby on Rails, the front-end looks like a pretty standard reactive App, maybe even done in React or Vue you might think. So what’s the deal? Well…
Do you want to stay in wonderland?
Let’s look at some code
app/views/converter/index.html.erb<input placeholder="type in Korean (일십삼) or plain numbers (105)" data-reflex="input->ConverterReflex#input" value= <%= @input %>> </input>Result: <%= @out %>
This is all that is necessary for a reactive frontend. We need to tell a data-reflex attribute which Ruby class will handle which client-event. The event here is “input” (check html5 events for more like i.e. click), the Ruby class and accompanying method is “ConverterReflex#input”, that’s just like controller methods in rails!
Next is the other side, something what is called a reflex. I don’t want to go into the gory details of converting Korean numbers, so I went with a simple reverse of the input.
/app/reflexes/converter_reflex.rbclass ConverterReflex < ApplicationReflex
@out = element[:value].reverse
The element variable here is the input field which triggered the reflex, we simply reverse the value and put it into a instance variable named @out, which is rendered in the view you saw previously.
This is accomplished with a Ruby on Rails framework called Stimulus-Reflex:
We extend the capabilities of both by intercepting user interactions and passing them to Rails over real-time…
Definitely check out the framework if this sounds remotely interesting and you want to stay in wonderland, for just a little longer.
If you’re interested in Korean numbers: peterlamber/koreanumbers
Thanks for reading