I'm pretty new to Ruby and I'm looking for an enum-like-type just to
make my code more readeable, but maybe I'm taking a wrong approach
(badly influenced bu others languages I know, no names please :-)) and
going against some ruby pragmatic principles, don't know.
Anyway, if you do know something in the language that might help to
accomplish modeling enums like the example below, in a more clever
way,
I'll appreciate the tip.
The common usage is Symbols. Read about them at:
http://phrogz.net/ProgrammingRuby/language.html#symbols
http://www.ruby-doc.org/core/classes/Symbol.html
You can then use them like:
def foo(action)
case action
when :do_this ...
when :do_that ...
Else raise "unknown action #{action}"
end
end
foo(do_this)
doo(do_something_else)