
21 Ruby Tricks You Should Be Using In Your Own Code - pauljonas
http://www.rubyinside.com/21-ruby-tricks-902.html
======
gaius
The more exposure to Ruby I get, the more convinced I am that in 5 years it
will be a maintenance nightmare of Perl-like proportions.

A culture that prizes cleverness over consistency is an evolutionary dead-end,
this transcends the merits of the technology.

~~~
hassy
Thinking out loud: could this desire for "cleverness" stem from the fact that
most Ruby programmers work on webapps?

~~~
gaius
This is purely my personal experience, mind, but I have observed that Ruby
users tend to be younger and webbier and employed mainly to code, and Python
users tend to be older and employed to do other things, of which coding is a
subset. This explains the cultural differences; Python users have been burnt
before by unmaintainable codebases and are determined not to make the same
mistake twice. Also, as Python users (again, in my experience) tend not to be
primarily programmers, they aren't impressed by clever coding tricks.

------
tptacek
... if you want your Ruby code to look more like Perl.

~~~
ambition
I share your hesitation. Those that are little-known tricks would cause any
reader to do a double-take.

~~~
raganwald
Very true, however Ruby is still very much growing in popularity and growing
as a language. Therefore, if you employ a "little-known trick" and somehow it
becomes popular, it is no longer little-known and it becomes a "standard
idiom."

This is not automatic, but I suggest the possibility is much greater with Ruby
than with certain other languages for various reasons, and therefore it is at
least worth considering a new idiom in Ruby rather than rejecting it outright.

One of the ways you can make your favourite idiom popular is to blog about it,
of course. Or perhaps to write something really popular and use your idiom in
it, such as returning() {...} or perhaps Symbol#to_proc.

<http://weblog.raganwald.com/2008/02/1100inject.html>

------
jrockway

        if __FILE__ == $0
          # Do something.. run tests, call a method, etc. We're direct.
        end
    

That works great... until you execute the script via a symlink.

~~~
zenspider
wrong. have you bothered trying what you're claiming to be true?

    
    
        % ./blah.rb; ./hah.rb 
        blah
        blah
        % cat blah.rb
        #!/usr/bin/ruby
        
        if __FILE__ == $0
          puts "blah"
        end
        % ls -F hah.rb
        hah.rb@

~~~
altano
Doesn't work on OSX for me.

Errrr, oh no wait... it does.

