6 ms·
Ruby is neat! Except for this part: return nil unless other.is_a?(self.class)
by ldubinets 13y ago
Ruby is neat! Except for this part:
return nil unless other.is_a?(self.class)
- klibertp 13y agoWait, why? Try to read it aloud and it will make sense. I've seen lot's of hard and confusing syntax but this is not one of them. And I'm not a Ruby developer.
- cheald 13y agoPost conditions are odd if you're not used to them, but once you start to mentally allow for them, they're really quite nice.
- ldubinets 13y agoAh, seems everybody misunderstood my comment (not hard to see why). It's not the post conditions that bother me, its the dynamic typing! In my opinion, ruby's duck typing really only works until you actually need it.
- xentronium 13y agoIs it a statement-modifier 'unless' that bothers you? `return ... unless ...` is kind of idiomatic way of returning early in the function. You get used to this shortcut ridiculously fast.
- Groxx 13y agoI'm a fan of: while true do puts 'lol' end unless true but seriously, I like postconditions. they're also handy for encoding intent, if you have a pattern of the left-hand-side being the primary logic flow.
- waxjar 13y agothis can also be written as other.is_a?(self.class) || return if you prefer that.