Tag: ruby

  • Rails’ and Ruby’s Hash transform_values

    Rails: 4.2.1-5.2.3 and Ruby >= 2.5.5 have a transform_values method on Hash that allows you to pass a block to the method and transform the values of the key-value map in the hash based on the block contents. Essentially, it’s map but for the Hash values only, and with no weird Hash/array-element syntax. From the…

  • NoMethodError undefined method `shared_examples_for’ for main:Object for bundle gem rspec

    undefined method shared_examples_for for main:Object in rspec for bundle gem generated rspec file.

  • Ruby: Enumerable grep, grep_v

    UPDATE: After I wrote this, I started finding myself doing a lot of caller.grep(/(project_directory|suspected_gem)/) to aid in debugging obscure interactions with internal gems and projects. In looking at a pull request and noticing some awkward “first” and “last” iteration detection which also required each_with_index, I started looking into what would be a cleaner way, and…