3 ms·
I'm not sure this really sells what's best about Ruby. Python and many other languages offer very similar tools, and the example given is nowhere near idiomatic
by grey-area 13y ago
I'm not sure this really sells what's best about Ruby. Python and many other languages offer very similar tools, and the example given is nowhere near idiomatic Ruby anyway - it should be using attr_accessor as others have pointed out. I can't see that this is markedly different from many other languages which now have shortcuts for accessors.
method_missing is interesting because it has been criticised in projects like Rails, precisely because it leaves you with an API which isn't documented explicitly in the code. As Rails matures they've moved away from dynamic finders, and more towards defined methods which take options, so instead of
Post.find_all_by_xxx or Post.find_by_xxx
People often use:
Post.where(xxx)
I've never been tempted to use it explicitly myself, in quite a few years of using Ruby, it just feels too hacky somehow and too akin to monkey-patching, another early Ruby practice which Rails has moved away from.
In contrast I do love the automatic accessors (not as shown in this post) in Ruby and the philosophy that everything should be as simple and predictable as possible, just having to edit header files is so jarring when going back to something like Obj-C. Ruby feels comfortable to me mostly because of the attitude of the language and the standard library which is pretty surprise free and covers most of the bases, but it's not markedly superior or different IMHO from other languages like Python, and choosing between them is really a matter of taste.