Double inject. What does it mean?
i want to know how long it takes to do some stuff. I've got some code like this:
def count_stuff(list) list.inject() do |results, item| results << get_results_from_something_else(values) end.flatten.uniq
I needed a URL validator - it needed to check that URL's had HTTP or HTTPS at the beginning. I initially wrote a "before save" action, but didn't like it cluttering up my model. I found a reference to basically "monkey patching" Rail's default Validator class, so that's what I did!
# concerns/url_validator.rb require 'uri' class UrlValidator < ActiveModel::Validator def validate(record) if record.url?
A few days ago, I worked on a project that was mostly about serving up basic store data (modeled after Etsy) to an API.
We had a few dozen end-points, and all responses were in JSON.
Most of the action happened inside of our controllers, and as you might imagine, our
routes.rb file was bananas.
One of the instructors made an exceptionally simple suggestion, I was embarrassed to not have seen it.
Learning is cool.
Learning how to learn is a super power.
Lets look at the lense of learning a new language:
At the most tactical level, we would be studying the language itself. Reading a children's book in the target language, or making and studying flashcards.
At a higher level, we would be considering how we can best study the language. Flash cards? Reading children's books in the foreign language? Passive or active learning? etc.
I'd like to alias
awesome_print + the
_ command in
rails console to
pp. In other words, I'd like
pp[return] to function the same as
As I'm spending more and more time in a rails console session, I'd like to be able to use awesome print to regularly evaluate objects.
I know I can enter
ap _ at any time to return the prior object in
awesome_print's sweet formatting, but I want to map
ap _ to
it takes six keystrokes (including
return) to hit
ap _, but only three for
pp. The problem is, I couldn't figure out a way to alias this inside of my