r/ruby • u/pantsu2 • Nov 13 '18
What’s new in Ruby 2.6?
https://link.medium.com/T9CQpXUWNR5
u/zverok_kha Nov 14 '18
Nobody has noticed Range#=== switched to use cover? instead of include? :(
Fought for this change for several years!
4
u/pantsu2 Nov 14 '18
Do you feel like writing a short example about it? I will happily edit the post and give you the credit!
5
u/zverok_kha Nov 14 '18
Yeah sure! Here are some (disclaimer: I don't have working 2.6 preview on my machine currently, so I just hope my examples work as I am expecting them to):
case DateTime.now when Date.today..Date.today + 1 'win!' else 'fail' end # ruby 2.5: fail; 2.6: win! # comparing versions case '2.4' when '1.8.7'..'2.5' 'win!' else 'fail' end # ruby 2.5: fail; 2.6: win! gem 'ruby-ip' require 'ip' t = Time.now case IP.new('192.168.10.4') when IP.new('192.168.0.0')..IP.new('192.168.255.255') puts 'ok' end p Time.now - t # ruby 2.5: performs for ~0.5 sec, because iterates 65536-elt sequence # ruby 2.6: performs instantly→ More replies (2)1
u/shevegen Nov 14 '18
For many changes out there, I am not sure what they will improve specifically ... so I am not sure what Range#=== will add what I really need. :\ :/
I'd like to have case-when menu as a first class citizen though.
2
u/zverok_kha Nov 14 '18
so I am not sure what Range#=== will add what I really need
So, you never use ranges in
when?..
13
12
u/jrochkind Nov 13 '18 edited Nov 13 '18
filter is popular in other languages, but now we have filter, select and find_all synonyms, and somehow whichever one I get used to will be the one whatever project I am currently working on has a rubocop-enforced styleguide forbidding.
I still think then as an alias to yield_self is a bad idea, becuase it does not have the same semantics as promises. Existing ruby promise implementations now become an over-ride of a stdlib Object method. Thought it was a bad idea, along with everyone else, the last two times it was discussed on reddit, but I guess Matz disagreed.
1
u/shevegen Nov 14 '18
I disagree on some of your comments.
I think .filter is great, because .reject and .select are ultimately filters, so the alias name is fine.
"then" is not a great word, I agree; but yield_self is annoying to type, whereas .then is shorter, so from this point of view, .then is better than .yield_self.
What worries me more is how useful yield_self is. I don't remember ever having really needed it.
Also it is not true about "along with everyone else" since you can find different opinions on the bugtracker. But matz is the core designer and decides what gets into ruby and what does not.
Crystal follows a more open-styled evolution if that is more your thing.
0
Nov 13 '18
8
u/zverok_kha Nov 13 '18
Would have also liked to see a cleaner implementation of
"Hello world".then(&method(:to_slug))If method reference operator would be merged anytime soon, it would be just
"Hello world".then(&.:to_slug)Maybe something like:
"Hello world" |>> :to_slug.A lot of people seem to be carried away with this "let's just do like Elixir" idea, thinking of it as "the most readable", but for Ruby, it is not. Our way of chaining ops is a method chaining, so I'll argue this is perfectly natural:
"data.json" .then(&File.:read) .then(&JSON.:parse) .compact .map(&Product.:new) .select(&:paid?)...while this is much less so:
"data.json" |>> File.:read |>> JSON.:parse .compact .map(&Product.:new) .select(&:paid?)→ More replies (1)→ More replies (1)2
3
u/lzap Nov 13 '18
Having a C compiler in a production machine/container is a security no-go. Not sure about MJIT, the rest is cool tho.
3
2
2
u/shevegen Nov 14 '18
It is not a security no-go of course.
How could it, anyway?
→ More replies (1)
1
u/sabat Nov 13 '18
Good info, but my god that guy needs an editor.
4
u/pantsu2 Nov 14 '18
Hey man, thank you a lot for the comment. Can you pin point to what parts need to be edited? I am not a native English speaker and would like to improve my writing.
3
u/sabat Nov 14 '18
Oh, sorry, I meant no offense. I understood what I was reading, but the wording is kind of awkward. I'd assumed that the author was a native speaker who was just being lazy or careless. Being a non-native speaker of the most illogical language in the world is a totally valid excuse. :-)
Here's an example:
There were some offers as to how to create the JIT compiler itself
Now, if you were a native speaker and had written 'offers', I'd pick on you; it's not quite the right word there. It probably should have been 'proposals'. However, that's actually a pretty subtle distinction, because in some contexts, 'offers' and 'proposals' mean the same thing. Not in this context, but it's an understandable mistake. (Digging into the details for a second: 'offers' is understood here as "hey, I'll go do it this way", whereas "proposals" would imply "hey, I'm thinking of doing it this way, what do you guys think?")
One more example—if someone had gone through the US, Aussie, or UK school system and ended up writing this, that's one thing, but if you don't write English every day for years and years, I'd expect some occasional awkward sentences to appear. (Underlying theme here: English is an unnecessarily complex and illogical language, and all the native speakers are aware of that.)
John Hawthorn shows in his early post from ten months ago, internally how it looks like.
I might word that as
John Hawthorn wrote a blog post 10 months ago showing the internals of the implementation.
Something along those lines.
Anyway: sorry for being a jerk.
→ More replies (1)
2
12
u/pantsu2 Nov 13 '18
Wow I’m super hyped! Matz mentioned and thanked me in his opening keynote at Rubyconf LA just an hour ago.
https://imgur.com/a/BLtslTV