
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
= heredoc_unindent
== DESCRIPTION:
This gem removes common margin from indented strings, such as the ones produced by indented heredocs. In other words, it strips out leading whitespace chars at the beggining of each line, but only as much as the line with the smallest margin.
It is acknowledged that many strings defined by heredocs are just code and fact is that most parsers are insensitive to indentation. If, however, the strings are to be used otherwise, be it for printing or testing, the extra indentation will probably be an issue and hence this gem.
== SYNOPSIS:
if true s = <<-EOS How sad it is to be unable to unindent heredocs EOS t = <<-EOS.unindent How wonderful it is to be able to do it! EOS end
s[0..12] #=> " How sad" t[0..12] #=> "How wonderful"
s = " foo" #=> " foo" s.unindent! #=> "foo" s.unindent! #=> nil s #=> "foo"
u = " 1\n \n\n" u.unindent == u #=> true u.unindent(ignore_empty: true) #=> " 1\n\n\n" u.unindent(ignore_blank: true) #=> "1\n\n\n"
== FEATURES:
== REQUIREMENTS:
== INSTALL:
== DEVELOPERS:
After checking out the source, run:
$ rake newb
This task will install any missing dependencies, run the tests/specs, and generate the RDoc.
== ACKNOWLEDGEMENTS
The initial implementation was based on the answer by Rene Saarsoo to the question {how do i remove leading whitespace chars from ruby heredoc}[http://stackoverflow.com/questions/3772864/how-do-i-remove-leading-whitespace-chars-from-ruby-heredoc].
== ALTERNATIVES
Despite minor API differences or edge-case behaviour, the following gems implement equivalent unindenting functionality:
=== So why another one?
Well, the fact is that the author only found about the other gems after he had already implemented the initial version of heredoc_unindent. And it was for the good, as benchmarking revealed that heredoc_unindent is by far the most efficient of them, both memory and processor-wise.
=== Efficiency!
Depending on the Ruby implementation, heredoc_unindent is is about 1.6--2.4x faster than {unindent}[http://rubygems.org/gems/unindent], 1.9--6.6x faster than {indentation}[http://rubygems.org/gems/indentation], and 4--19x faster than {outdent}[http://rubygems.org/gems/outdent]. In addition, heredoc_unindent has the lowest memory consumption, requiring only between a fifth and a sixth of the competitors.
== LICENSE:
(The MIT License)
Copyright (c) 2011 Adriano Mitre
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
We found that heredoc_unindent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.