This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ArrayInquirer | |
| def method_missing method, *args | |
| begin | |
| select { |elem| elem.send :"#{method}?", *args } | |
| rescue NoMethodError | |
| super method, *args | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %body | |
| %nav.main | |
| %ul | |
| %li= link_to 'main 1', some_path, class: active_navigation_item?(:main) # => true | |
| %li= link_to 'main 2', some_path, class: active_navigation_item?(:more) # => false | |
| = yield |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # returns a ranking as a hash { elem => rank } | |
| # ranks based on the sort order of the values the given block yields | |
| # elements yielding the same value are ranked the same | |
| module Enumerable | |
| def rank_by | |
| inject(Hash.new {|h, k| h[k] = []}) { |h, e| h[yield(e)] << e; h } | |
| .sort.each_with_index | |
| .inject({}) { |h,((_, es), i)| es.each { |e| h.update e => i + 1 }; h } | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Path to your oh-my-zsh configuration. | |
| export ZSH=$HOME/.oh-my-zsh | |
| # Set to the name theme to load. | |
| # Look in ~/.oh-my-zsh/themes/ | |
| export ZSH_THEME="robbyrussell" | |
| [[ -s "$HOME/.rvm/bin/rvm-prompt" ]] && export RPROMPT="\$(~/.rvm/bin/rvm-prompt)" | |
| # Set to this to use case-sensitive completion | |
| # export CASE_SENSITIVE="true" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Abyss | |
| ROUNDTRIP = {}.tap { |abyss| abyss.default = abyss }.freeze | |
| def to_abyss(obj = self) | |
| case obj | |
| when Hash | |
| obj.inject({}) { |h,(k, v)| h.update k => to_abyss(v) }.tap { |h| h.default = ROUNDTRIP } | |
| when Array | |
| obj.map { |e| to_abyss(e) } | |
| else | |
| obj |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'active_support/concern' | |
| module MyCustomFoo | |
| extend ActiveSupport::Concern | |
| def foo_with_custom | |
| puts 'custom' | |
| foo_without_custom | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config.treat_symbols_as_metadata_keys_with_true_values = true | |
| config.filter_run :focus | |
| config.filter_run_excluding :slow | |
| config.run_all_when_everything_filtered = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # vim FTW | |
| Pry.config.editor = "mvim" | |
| # Prompt with ruby version | |
| Pry.prompt = [proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }] | |
| if defined?(Rails) && Rails.env | |
| begin | |
| extend Rails::ConsoleMethods if defined?(Rails::ConsoleMethods) | |
| require "rails/console/app" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module CSVMappings; ... end | |
| module NavisionFtpsConnection; ... end | |
| class CSVImporter | |
| include ... | |
| def initialize(file, clear, sep, etc...) | |
| @file = file, ... | |
| end | |
| def import |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module LinkToCondHelper | |
| # Alternative to link_to_if that actually works the way you expect | |
| # when using a block: If the condition passes wrap the block with a link. Otherwise just render it. | |
| # @param [Boolean] cond Condition to check if block should be linked or just rendered | |
| def link_to_cond cond, *args, &block | |
| if cond | |
| link_to *args, &block | |
| else | |
| capture &block | |
| end |