I’ve been watching some great RubyConf talks recently, and Matz (creator of Ruby) is always fun to watch. He went over some new features in Ruby 2.3.0, so I thought I’d re-report them here for everyone. This is the talk I got them from.
grep is a Unix command for pattern matching. For example, if I wanted to check my history for a recent ssh IP address, I could try something like:
grep -v is the inverse - you’ll get all the results that don’t match. I am imagining it is used like so:
Stricter version of Hash#values_at. Check out the feature request here.
> 0 !
<=, <, >=, >
This seems odd, but it
A >= B is another way of asking if hash A contain all of B and possibly more.
Here’s an example straight from the talk:
Just a ruby interpreter helper for typos on methods. Doesn’t seem very useful to me.
Frozen string crap
Strings will be frozen by default I think. This frees up space or something. Feels inconvenient, so I hope the gains are worth it!
Safe navigation with
Look, it’s a guy sitting on the floor staring at a dot! The ‘lonely operator’! This one is really useful:
This is also another very useful feature in Ruby 2.3. It’s unsafe to check arrays or hashes at depth for values if you aren’t sure they’ll be there, because you’ll get an error once a nil comes up. Now, there’s a safe
dig method available, and it’s not unsimilar to the aforementioned
Another really common need, at least for me, is the opposite of this
dig which I’m calling
bury. I actually tweeted to @Matz about this feature request and posted to the Ruby lang redmine forum thing.
bury allows you to insert an object at an arbitrary depth into an array or hash:
My feature request actually got a few comments!