Stimulus.js adds inbuilt support for stopping event propagation and preventing default action

It's very common in Stimulus.js to call the .preventDefault() or .stopPropagation() methods on an Event object immediately after a controller's action has been fired: import { Controller } from "@hotwired/stimulus"; export default class extends Controller { open(event) { event.preventDefault(); /* ... action logic ... */ } close(event) { event.stopPropagation(); /* ... action logic ... */ } } But it starts to feel repetitive after a while; which is why a PR introduced by yours truly to the hotwired/stimulus repo makes it so that you can do those things while defining the action descriptors themselves: <div data-controller="modal"> <a data-action="modal#open:prevent">Open</a&

Rails 7 brings Import Maps into the limelight

Rails 7 puts forward an alternative approach to bundling JS called Import Maps. Read this blog to find out more about it.

Integrating The Silver Searcher with Vim's 'grepprg' (without any plugins)

Vim has a command called :grep (:help :grep), which is used for searching plain text across the project. Internally it uses the *nix grep utility to perform the search. However, the grep utility is very slow, especially for larger projects, which means you might want to use something else like ag (follow the instructions given in the official repo for installation). Understanding :grepWhen we execute let's say :grep text_to_find in Vim, it will look at the value of the option called 'grepprg' (:help 'grepprg'), replace $* with text_to_find, and then pass it to the shell for execution.

The Many Faces of Ruby's Top-level

In the previous post, we looked at how Ruby's top-level acts as a wrapper of the Object class. And that the definitions you put in the top-level act as if they were put in the Object class itself. But, there was one thing that I left out in that blog post, because it deserves its own attention. Module extensionIf you have a module: module Foo def bar :bar end endand you extend it in the top-level: extend Fooyou'd expect that it would extend the Object class because of what we saw in that previous post. But you'd be wrong! Object.

Ruby's Global Scope is Not Really Global

Ruby does not have any entry point to the code it is executing. Compare that to other languages like C, C++, Java, etc., which has a main() method in some way. And this main() is the entry point to the code. But in Ruby, we can open a file with a .rb extension and write our code at the top-level like: foo = 'Great Scott!' puts foo # => Great Scott!... and Ruby will execute the file for us. You'll get introduced to this top-level scope as global scope throughout most tutorials. Even though the intention is correct, the terminology as