Ruby: Return boolean for regex comparison
A collection of code snippets which return a boolean value for a regex comparison.
regexp.match?(string) # Recommended for Ruby >= 2.4
!!(string =~ regexp) # Recommended for older Rubies
regexp === string
!(regexp !~ string)
The Ruby 2.4 method
Regexp#match?
Show archive.org snapshot
does not set globals like $~
or $1
, so it should be more performant.
Related cards:
Ruby: A small summary of what return, break and next means for blocks
Summary
- Use
return
to return from a method.return
accepts a value that will be the return value of the method call. - Use
break
to quit from a block and from the method that yielded to the block.break
accepts a value that suppl...
Remove resource fork files from a FAT volume on MacOS
Be careful!
The following solution will delete files on a volume. If you don't know exactly what you're doing, you can run into big trouble with your computer.
I play mp3 files on my car stereo that are stored on a SD-C...
Missing certificates for rubygems and bundler in Ruby 1.8.7
Using Ruby 1.8.7 you will not be able to use the maximum versions Rubygems 1.8.30 and Bundler 1.17.3 with https://rubygems.org/
anymore. This is a result of a server certificate on December 5th, 2020. The resulting errors will...
Objective-C for Rubyists | PeepCode Screencasts for Web Developers and Alpha Geeks
If you know Ruby and you want to write applications for Mac OS X or the iPhone, you’re in a great place to start! This concise and content-packed 80-minute screencast will teach you what you need to know to start programming in Objective-C.
Fun with Ruby: Returning in blocks "overwrites" outside return values
In a nutshell: return
statements inside blocks cause a method's return value to change. This is by design (and probably not even new ...
List RubyGems binary version for all installed Ruby versions
rbenv
To check which rubygems versions your different rbenv rubys are using, you can use this small bash script:
for i in $(rbenv versions --bare); do rbenv shell "${i}"; echo -n "ruby ${i} has gem version: "; gem -v; done
RVM
``...
Regular Expressions - Cheat Sheet
You can write regular expressions some different ways, e.g. /regex/
and %r{regex}
. For examples, look here.
Remember that it is always a good idea [to matc...
RubyMine: Fixing "Rubocop returned exit code -1. See the logs for details"
When RubyMine reports Rubocop returning "exit code -1", upgrading Rubocop can be the fix:
gem install rubocop
"The logs" can be accessed with Ctrl + Shift + A > Show log in (Files). This opens your file manager at the IDEA log location; t...
Installing RubyGems for Ruby 1.8.6
Since version 1.5 RubyGems requires at least Ruby 1.8.7. The last one working with Ruby 1.8.6 was RubyGems 1.4.2.
You get still download it from their servers and [install RubyGems]...
Breaking changes for boolean attributes in HAML 6
Haml 6 has some breaking changes regarding boolean attributes.
Only the following attributes and
aria
/data
attributes are considered boo...