Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any Ruby language features you avoid?

Tags:

syntax

ruby

It seems to me like Ruby has a lot of syntactic flexibility, and many things may be written in several ways.

Are there any language features/syntactic sugar/coding conventions that you avoid as a Ruby programmer for clarity? I am asking about things that you choose not to use on purpose, not stuff you still have to learn.

If your answer is, "I use everything!," do you ever comment code that would be otherwise obvious if the reader knows the relevant Ruby syntax?

[I'm particularly interested in Ruby in a RoR context, but everything is welcome.]

like image 312
Dan Rosenstark Avatar asked Jun 04 '09 09:06

Dan Rosenstark


4 Answers

The whole range of "$" globals (see Pickaxe2 pp333-336) mostly inherited from Perl, are pretty ghastly, although I have on occasion found myself using $: instead of $LOAD_PATH.

like image 75
Mike Woodhouse Avatar answered Oct 27 '22 16:10

Mike Woodhouse


I generally refrain from going overboard with monkey patching because it could lead to some maintainability and readability issues. It's a great feature if used correctly, but it's easy to get carried away.

like image 24
Firas Assaad Avatar answered Oct 27 '22 17:10

Firas Assaad


The for ... in ... loop. It directly compiles to obj.each (and throws a strange error message accordingly) and is totally unnecessary. I don't even see where it improves readability - if you've been around ruby for more than a week, #each should be natural.

like image 7
Skade Avatar answered Oct 27 '22 15:10

Skade


This might be obvious but I generally avoid using eval if there's any alternative.

like image 6
Sam Avatar answered Oct 27 '22 17:10

Sam