Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
That’s it! There’s obviously things that could be improved here (e.g., create a parent controller for inbound/outbound controllers to inherit from, DRY up the _stations.html.erb partial, etc.), but I never claimed this was a perfect example. If you want to look at the code more closely, please reference the GitHub repository. And if you want to go even further beyond, stay tuned for the next installment of our Metaprogramming in Ruby series!
We can then add the data into our view using a partial that I’ll call _stations.html.erb. I’m using tailwindcss here, but the styling is immaterial for this example.
It is very seldom the case that metaprogramming is the only answer to a given problem. The notable exception to this would be if you wanted to write a domain-specific language (DSL) or framework, such as Rails. In that case, yes, you’ll probably be living and breathing metaprogramming.