Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ruby is a joy to program in. I started exploring it after using Haskell and Smalltalk and was pleasantly surprised when the language would do things like both of them.


fwiw As someone without Ruby programming skills, my experience was that it does unpredictable "magic" things, which I did not find helpful when writing mundane code. fwiw


Here are four small things to remember when working with Ruby:

1. Everything is an object and the main thinking is that you send messages to objects not call methods on objects. This is very important and the core of how the language works and moreso important when reading Ruby code.

2. `false` and `nil` are falsey. Everything else is truthy when used directly in conditionals. Eg: if variable will go on true-branch when variable is anything else than `false`/`nil`. Else it will go on the else-branch.

3. Start irb (the interactive console) and use <object>.inspect + <object>.class to see what is happening. Ruby has great introspection. Remember the first thing I said here (everything is an object) so you can inspect almost anything.

4. In Ruby paranthesis are optional. Eg: user.upgrade_to "admin" is actually user.upgrade_to("admin")


Was it in a Rails app? I'm not sure what magical things standard lib Ruby would do but Rails does a lot.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: