Created
November 13, 2013 21:35
-
-
Save invisiblefunnel/7456808 to your computer and use it in GitHub Desktop.
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
| # https://github.com/rails/rails/blob/e20dd73df42d63b206d221e2258cc6dc7b1e6068/activesupport/lib/active_support/core_ext/object/try.rb | |
| class Object | |
| def try(*a, &b) | |
| if a.empty? && block_given? | |
| yield self | |
| else | |
| public_send(*a, &b) if respond_to?(a.first) | |
| end | |
| end | |
| end | |
| class NilClass | |
| def try(*args) | |
| nil | |
| end | |
| end | |
| # https://github.com/rails/rails/blob/e20dd73df42d63b206d221e2258cc6dc7b1e6068/activesupport/lib/active_support/core_ext/string/strip.rb | |
| class String | |
| def strip_heredoc | |
| indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0 | |
| gsub(/^[ \t]{#{indent}}/, '') | |
| end | |
| end | |
| puts <<-CHARS | |
| A | |
| B | |
| C | |
| D | |
| CHARS | |
| # A | |
| # B | |
| # C | |
| # D | |
| puts <<-CHARS.strip_heredoc | |
| E | |
| F | |
| G | |
| H | |
| CHARS | |
| #E | |
| # F | |
| # G | |
| # H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment